Redirect the request to the page, not to the application page

I made an application, this application is on the fanpage tab. But when someone invites their friends, the invitation is redirected to the application page, and not to the fanpage tab.

I use this:

function invite(){  
FB.ui({
    method: 'apprequests',
    message: 'message',
    data: 'tracking information for the user'
},
    function(response) {
        location.href="CANVAS_URL?req="+response.request_ids;
       }
);

In my application configuration, I have:

Canvas url: url on my website

Url tab: url on my website

How can i do this?

+3
source share
3 answers

If you use PHP, you can use the $ _SESSION variables.

<?php
session_start();

$app_token = '?'.file_get_contents('https://graph.facebook.com/oauth/access_token?client_id='.FACEBOOK_APP_ID.'&client_secret='.FACEBOOK_SECRET.'&grant_type=client_credentials');

if ( isset($_GET['request_ids']) && !empty($_GET['request_ids']) ) {
    $_SESSION['request_ids'] = $_GET['request_ids'];
            header('Location: ' . FACEBOOK_PAGE_TAB );
}

if ( isset($_SESSION['request_ids']) && !empty($_SESSION['request_ids']) ) {
    if ( strpos($_SESSION['request_ids'], ',') !== false ) {
        $request_ids = explode(',', $_SESSION['request_ids']);
        $_SESSION['request_ids'] = $request_ids[0];
        var_dump($_SESSION['request_ids']);
    }
    $request = json_decode(file_get_contents('https://graph.facebook.com/'.$_SESSION['request_ids'].$app_token));
    var_dump($request);
}
?>

$ _ SESSIONS seem to be the best solution when you make the transition between apps.facebook.com/yourapp/ and facebook.com/yourpage/?sk=app_123456 and vice versa.

Greetings

+3
source

I had a similar problem. This is what I did:

PHP, URL- ...

if(isset($_GET["request_ids"]))
{
    $page_id = 123;
    $app_id = 321;
    $url = "http://www.facebook.com/pages/FAN_PAGE/$page_id?sk=app_$app_id";
    ?>
    <script type="text/javascript">
        top.location.href = "<?=$url?>";
    </script>        
    <?            
    exit;
}

, ,

+2

Go to the fanpage application tab, copy this URL and paste it into the "Bookmark URL" field in the settings of your application.

Users responding to apprequests will then be redirected to the fanpage tab.

+1
source

All Articles