2012-03-08 82 views
0

我有一些奇怪的问题构建Facebook的iframe应用程序。该应用程序似乎陷入了无限循环转到应用程序页面。Facebook的PHP SDK 3.1.1“错误验证访问令牌”后去转到应用页

用户在转到应用程序页面授权应用程序并返回到应用程序后,/ me api调用将引发“验证访问令牌的错误”异常。我检查并且在签名请求中有一个有效的访问令牌(使用facebook访问令牌调试工具进行测试)。我试图用setAccessToken()方法设置失败。 getUser()方法成功返回用户标识,但它仍挂在/ me api调用上。

这不会发生在每个浏览器中,我只是在Chrome中看到它,有时并不清晰。我使用P3P标题在IE中修复了它。它在Firefox中正常工作。

我几乎卡住了,我头发拔出,所以任何想法都欢迎。非常感谢。

完整的错误消息:“验证访问令牌的错误:您无法访问该应用程序,直到您登录到www.facebook.com并按照给出的说明进行操作。”

下面的代码。

$this->_facebook = new Facebook(
    array(
     'appId' => $this->_config['appId'], 
     'secret' => $this->_config['secret'], 
     'cookie' => true, 
     'fileUpload' => true 
    ) 
); 

$this->_signedRequest = $this->_facebook->getSignedRequest(); 

// Doing something with signed request, not FB related 

$this->_userId = $this->_facebook->getUser(); 

if($this->_userId) { 
    try{ 
     // At this line the "Error validating access token" error shows up 
     $this->_user = $this->_facebook->api('/me'); 

     // Some more irrelevant code here 

    } catch (Exception $e){ 
     $this->_facebook->destroySession(); 
     $this->_facebookLogin(false); 
    } 
} else { 
    $this->_facebook->destroySession(); 
    $this->_facebookLogin(false); 
} 

// The _facebookLogin method 
public function _facebookLogin($perms = 'email,user_birthday,publish_stream,video_upload'){ 
    $data = array(
     'fbconnect' => 0, 
     'redirect_uri' => 'aredirecturl.com' 
    ); 

    if(!empty($perms)) { 
     $data['scope'] = $perms; 
    } 
    echo '<script type="text/javascript">window.top.location.href = "'.$this->_facebook->getLoginUrl($data).'";</script>'; 
    exit; 
} 
+0

你可以把你的完整代码(例如在这个代码中'公共函数_facebookLogin'是错误的 – 2012-03-09 20:38:34

+0

我面临同样的问题,铬也是如此。@Cazacu弗拉德如果你找到解决方案,请在这里发帖谢谢 – 2012-09-09 00:24:57

回答

0

编辑这部分

// At this line the "Error validating access token" error shows up 
$this->_user = $this->_facebook->api('/me'); 

这个

// At this line the "Error validating access token" error shows up 
$this->_user = $this->facebook->api('/me','GET'); 
+0

感谢您的答案,但是没有做到这一点。就我所见,GET是图形调用的默认设置,所以它已经在使用它了。 – 2012-03-09 11:13:01

0

什么手工摧毁你的会议?你调试过这些参数吗?

unset($_SESSION['fb_'.$YOUR_API_KEY.'_code']); 
unset($_SESSION['fb_'.$YOUR_API_KEY.'_access_token']); 
unset($_SESSION['fb_'.$YOUR_API_KEY.'_user_id']); 
unset($_SESSION['fb_'.$YOUR_API_KEY.'_state']); 

我几乎使用相同的代码如你,但我不使用fileUpload和cookie的参数。

相关问题