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

10,747

Solution 1

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>";
   ?>

Solution 2

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.

Share:
10,747
Sergii Nester
Author by

Sergii Nester

Updated on June 23, 2022

Comments

  • Sergii Nester
    Sergii Nester almost 2 years

    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 ?

  • Sergii Nester
    Sergii Nester almost 13 years
    I did. Question is about "where" to redirect, not "how" to redirect. May be you've confused it with thousands "omg, how to redirect back to facebook" questions. Anyway, thnx for you time and answer. p.s. if you interested, i got this sorted out - forum.developers.facebook.net/viewtopic.php?pid=351648#p3516‌​48
  • user14322501
    user14322501 almost 13 years
    this verified my own thoughts, thanks Pav...good to know I can define my own redirect URI
  • Mikepote
    Mikepote over 12 years
    Could you please post the solution here, the facebook forum is not a stable place to keep the solution, it may be erased or removed from there.
  • rickyduck
    rickyduck about 12 years
    for the exact reason as what has happened now
  • markcial
    markcial almost 11 years
    @Mikepote yes, in fact, the answer has been deleted, is a shame i still have no clue about how to redirect from a gateway server after a successful login :(
  • Blake Frederick
    Blake Frederick over 9 years
    Arg the solution on the Facebook forum is now 404ing.
  • Blake Frederick
    Blake Frederick over 9 years
    So far from my searching I've found this to be the case.