简体   繁体   中英

Facebook App (canvas page) keeps redirecting to the index page

I am unable to figure out why every time I click on a link inside of my app (page 2 from page 1), it goes to page 2 but automatically redirects back to page one. This is getting frustrating. I feel like I have done everything correctly in the code below because it authenticates the user and everything as it should... but the only problem is, I can not navigate anywhere without it automatically going back to the index page.

$fb_app_id = "xxxxxxxx";
$fb_app_secret = "xxxxxxxxx";
$fb_scope = "email,user_birthday,user_location";
$fb_response_type = "token";
$canvas_page = "https://apps.facebook.com/app-name/";


require_once 'sdk/facebook.php';
$facebook = new Facebook(array(
  'appId' => '' . $fb_app_id . '',
  'secret' => '' . $fb_app_secret . '',
  'cookie' => true,
));

     $app_id = '' . $fb_app_id . '';
     $auth_url = "http://www.facebook.com/dialog/oauth?client_id=" 
            . $app_id . "&redirect_uri=" . urlencode($canvas_page) . ("&scope=" . $fb_scope . "&response_type=" . $fb_response_type . "");
     $signed_request = $_REQUEST["signed_request"];
     list($encoded_sig, $payload) = explode('.', $signed_request, 2); 
     $data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);
     if (empty($data["user_id"])) {
            echo("<script> top.location.href='" . $auth_url . "'</script>");
     } else {
            $UserId = $data["user_id"];
            $token = $facebook->getAccessToken();

            $facebook->setAccessToken($token);
            $user_profile = $facebook->api('/me/');
} ...

Can someone look at this and tell me what it is that I am doing wrong?

Thanks in advance!

Problem solved....

require_once 'sdk/facebook.php';
$facebook = new Facebook(array(
  'appId' => '0000000000000000000',
  'secret' => 'if-i-tell-ya-ill-have-to-kill-ya',
  'cookie' => true,
)); 
$canvas_page = "https://apps.facebook.com/whatever/";

 $auth_url = "http://www.facebook.com/dialog/oauth?client_id=" 
        . $fb_app_id . "&redirect_uri=" . urlencode($canvas_page) . ("&scope=" . $fb_scope . "&response_type=" . $fb_response_type . "");
     $signed_request = $_REQUEST["signed_request"];

$uid=$facebook->getuser();
if(empty($uid)){ echo("<script> top.location.href='" . $auth_url . "'</script>");}
else { // do something }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM