Facebook PHP SDK 3.1.1“;验证访问令牌时出错”;在转到应用程序页面之后


Facebook PHP SDK 3.1.1 "Error validating access token" after Go to App page

我在为Facebook构建iframe应用程序时遇到了一些奇怪的问题。该应用程序在"转到应用程序"页面上似乎陷入了无限循环。

用户在"转到应用程序"页面中授权应用程序并返回应用程序后,/me-api调用会抛出"验证访问令牌时出错"异常。我检查了一下,签名请求中有一个有效的访问令牌(使用facebook访问令牌调试工具进行了测试)。我尝试用setAccessToken()方法设置它,但没有成功。getUser()方法成功地返回了用户ID,但它仍然挂起在/me-api调用上。

这并不是在每个浏览器中都会发生,我只是在Chrome中看到它有时没有明确的模式。我在IE中使用P3P标头修复了它。它在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;
}

编辑此部件

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

手动销毁会话怎么样?你调试这些参数了吗?

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参数。