douchixu3686
2012-10-28 07:34
浏览 86
已采纳

Facebook授权(oauth)将应用程序重定向到iFrame(在php中)

My facebook app is getting redirected out of the iFrame on authorization. I have used the facebook.php and base_facebook.php from gitHub without any change and have pretty much followed example.php. What could I be missing?:

$facebook = new Facebook(array(
    'appId'  => $configParam['appId'],
    'secret' => $configParam['secret']
));
$appId=$configParam['appId'];
$user = $facebook->getUser();
if ($user==null) {
    $loginUrl = $facebook->getLoginUrl(array(
            'scope' => $perm
                ));     
    $loginUrl = $facebook->getLoginUrl();
    echo "<script type='text/javascript'>top.location.href = '$loginUrl';</script>";
}

The loginUrl is constructed in base_facebook.php as:

$this->establishCSRFTokenState();
$currentUrl = $this->getCurrentUrl();
return $this->getUrl(
'www',
'dialog/oauth',
array_merge(array(
        'client_id' => $this->getAppId(),
        'redirect_uri' => $currentUrl, // possibly overwritten
        'state' => $this->state),
      $params));
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • doumeng1897 2012-10-29 01:01
    已采纳

    It is a combination of things you have take care of to solve these two problems: 1. facebook authorization redirecting app out of iFrame (as mentioned by ifaour) 2. app going into a loop 3. app going into a loop only in IE

    For (1), everything must be consistently https (or http). I did have my secure canvas url as https but had left my canvas url as http (I thought this was fine). Apparently, both should be https

    For (2), the OOB facebook-php integration code at GitHub uses Current URL as redirect_uri. You have to change that to apps.facebook.com/namespace- note that that this has to be done at two places in base_facebook.php - getLoginUrl and getAccessTokenFromCode

    For (3) look at Why my FB app loops forever in IE?

    已采纳该答案
    打赏 评论

相关推荐 更多相似问题