我只获得Facebook用户的基本信息,但我需要更多

时间:2016-05-31 14:36:43

标签: php facebook facebook-graph-api facebook-php-sdk

这就是我致电login-callback.php的方式:

$permissions = ['email', 'user_likes', 'user_hometown'];
$helper = $fb->getRedirectLoginHelper();
$loginUrl = $helper->getLoginUrl('http://localhost:1234/fbtest/login-callback.php', $permissions);

echo '<a href="' . $loginUrl . '">Log in with Facebook!</a>';

这是我在login-callback.php内的登录操作:

if (isset($accessToken)) {
  // Logged in!
  $_SESSION['facebook_access_token'] = (string) $accessToken;

 $response = $fb->get('/me');
  $userNode = $response->getGraphUser();


  print_r($userNode);
echo 'data: ' . $userNode['name'];
echo '<br>';

}

输出如下:

Facebook\GraphNodes\GraphUser Object ( [items:protected] => Array ( [name] => xxxNAMExxx [id] => XXXXNUMBERSXXXXX ) )data: xxxNAMExxx

(我显然隐藏了我的身份证和真实姓名)

问题:为什么我的email数组中没有user_hometown$userNode这样的内容,即使我在$permissions数组中指定了name {1}}(ref)?我可以获得id因为它的设置,但除此之外School,还有其他内容......

我错过了什么吗?

1 个答案:

答案 0 :(得分:1)

您在API调用中缺少声明性字段:

<context-param>
    <param-name>javax.faces.FACELETS_REFRESH_PERIOD</param-name>
    <param-value>1</param-value>
</context-param>
<context-param>
    <param-name>javax.faces.PROJECT_STAGE</param-name>
    <param-value>Development</param-value>
</context-param>

更多信息:https://developers.facebook.com/docs/apps/changelog#v2_4