2

I am using the PHP SDK to handle my Facebook connects. Everything was working fine for some time but my script suddenly stopped working. Here is what happens:

$facebook = new Facebook(array('appId' => $app_id, 'secret' => $app_secret, 'cookie' => true));

$user = $facebook->getUser();

if ($user) {

    $permissions = $facebook->api('/me/permissions');

} else {

    $params = array();
    $params['scope'] = 'publish_actions,user_photos';
    header('Location: ' . $facebook->getLoginUrl($params));
    exit();

}

Returns: Fatal error: Uncaught OAuthException: An active access token must be used to query information about the current user.

The error is caused by the line

$permissions = $facebook->api('/me/permissions');

Any suggestions?

4

2 回答 2

0

你为什么不试试

$permissions = $facebook->api(
                '/me/permissions ',
                'GET',
                array(
                    'access_token' => $_SESSION['active']['access_token']
                )
            );
于 2012-12-11T10:23:22.927 回答
0

始终检查异常!这是一个简单的例子:https ://developers.facebook.com/docs/reference/php/facebook-api/

$user 返回当前用户的用户 ID,但是,这并不能保证用户没有同时注销或者他的令牌仍然处于活动状态。因此,不要仅仅依靠这个,因为你有一个 user_id,而是检查异常。您可以要求用户再次单击登录,或者在发生异常时自动将用户重定向到登录页面。

于 2012-06-20T21:14:13.267 回答