Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook App via PHP SDK - Redirecting back to page where someone added my app after getting permissions

Tags:

php

facebook

sdk

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.

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 ?

like image 840
Sergii Nester Avatar asked Jun 10 '11 03:06

Sergii Nester


People also ask

How do I grant permissions on Facebook?

Step 1: In Facebook, click the small arrow near your name in the upper-right-hand corner and choose Privacy Settings. Step 2: Scroll down to Apps and Web sites and click on Edit Settings off to the right. Step 3: If the app you want to adjust is in the recently used list, click on it to edit settings.

How do I give permission to an app on Facebook?

Tap in the top right of Facebook. Scroll down and tap Settings. Go to the Permissions section and tap Apps and Websites. Go to Apps, Websites and Games and tap Edit.


2 Answers

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>";
   ?>
like image 70
Pav Avatar answered Oct 10 '22 10:10

Pav


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.

like image 37
Mikepote Avatar answered Oct 10 '22 09:10

Mikepote