我收到错误"必须使用活动访问令牌来查询有关当前用户的信息"。似乎有很多文章和想法,但我很困惑,似乎事情也在改变。很多人说要使用离线访问,但这种情况似乎正在消失。我确实找到了这篇文章。
有人举过使用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();
试试这个(根据这个链接更改范围参数):
// 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
}