Facebook application via PHP SDK - redirect to the page where someone added my application after obtaining permissions

I have few problems. When I need an application to ask the user for permissions for the application, I use the following code:

<?php $loginUrl = $facebook->getLoginUrl( array( 'canvas' => 1, 'fbconnect' => 0, 'scope' => 'email,publish_stream,offline_access', )); ?> echo "<script type='text/javascript'>top.location.href = '$loginUrl';</script>"; 

I am working fine, but after the user clicks “grant permissions”, he is redirected to my application URL. I mean http://mydomain.com/myapp/ directly, not the page of my application on Facebook. I can get around this - I know my Facebook address, so I redirect it to the correct http://apps.facebook.com/myappname . It works fine too. BUT - when someone adds my application to the tab of a page - there is a problem. Because I don’t know where to redirect the user anymore - I don’t know which page my application was called from.

Is there any way to find out which page my application was called from or, even better, make Facebook correctly redirect the user to the facebook page, where the application tab is added after the "permission to access" dialog?

+6
source share
2 answers

You can set redirect_uri as follows:

  <?php $loginUrl = $facebook->getLoginUrl( array( 'canvas' => 1, 'fbconnect' => 0, 'scope' => 'email,publish_stream,offline_access', 'redirect_uri' => 'http://yourdomain.com/app', //the url to go to after a successful login )); echo "<script type='text/javascript'>top.location.href = '$loginUrl';</script>"; ?> 
+4
source

It seems the only thing you can do is to determine if the user is viewing your page outside of facebook, and then redirecting them to your facebook page.

+1
source

Source: https://habr.com/ru/post/890207/


All Articles