Facebook App via PHP SDK - Redirecting back to page where someone added my app after getting permissions
I have little problem. When I need my app to ask user to grant permissions to the app I use 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 works OK, but after user press "grant permissions" he is redirected to my app URL. I mean like http://mydomain.com/myapp/ directly, not my app page on Facebook. I can work around it - I know my app's Facebook address, so I redirect him to proper http://apps.facebook.com/myappname. It works OK too. BUT - when somebody adds my application on some page tab - here is where problem appears. Because I don't know where to redirect user anymore - I don't know, from what page my app was called. 开发者_JS百科
Is there any way to get to know, from what page my app was called, or, even better, to make Facebook properly redirect user to the "facebook page" where app tab were added after "grant permission" dialog ?
You can set redirect_uri
like so:
<?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>";
?>
Seems to be the only thing you can do is detect if the user is viewing your page from outside of facebook and then redirect them to your facebook app page.
精彩评论