Facebook App(画布页面)保持重定向到索引页面

时间:2013-10-13 04:54:29

标签: php facebook facebook-php-sdk facebook-canvas

我无法弄清楚为什么每次点击我的应用程序内部的链接(第1页的第2页),它都会转到第2页,但会自动重定向回第1页。这令人沮丧。我觉得我已经在下面的代码中正确地完成了所有事情,因为它验证了用户及其应有的一切...但唯一的问题是,如果不自动返回索引页面,我无法导航到任何地方。

$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/');
} ...

有人可以看看这个并告诉我我做错了什么吗?

提前致谢!

1 个答案:

答案 0 :(得分:0)

问题解决了......

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 }