4

我收到错误“必须使用活动访问令牌来查询有关当前用户的信息”。似乎有很多文章和想法,但我很困惑,似乎事情也在发生变化。很多人说要使用离线访问,但这似乎正在消失。我确实找到了这篇文章

有人有使用 PHP SDK 的示例吗?

我尝试做类似下面的事情,但它似乎不起作用;$FBuser仍然为零:

$token_url =    "https://graph.facebook.com/oauth/access_token?" .
                            "client_id=" . FB_APP_ID .
                            "&client_secret=" . FB_APP_SECRET .
                            "&grant_type=client_credentials";
list($name, $ACCESS_TOKEN) = explode("=", file_get_contents($token_url) );
$facebook->setAccessToken(ACCESS_TOKEN);
$FBuser = $facebook->getUser();
4

1 回答 1

0

试试这个(根据这个链接更改范围参数):

// Checks if the user granted the access (after the redirection bellow)
$user = $facebook->getUser();
if(!$user) {
    // If not: Retrieves the login url in order to redirect the user
    $url = $facebook->getLoginUrl(array('scope' => 'user_about_me', 'grant_type' => 'client_credentials'));
    // redirect here (after accepting the user will be redirect back to the same url. In other words this script, that will check again if the user is authenticated)
} else {
    // Now the user is authenticated
    $user_data  = $facebook->api('/me');
    $user_token = $facebook->getAccessToken();
    // Saves the access token
}
于 2012-09-08T21:31:28.947 回答