我有以下代码:
$fb = new Facebook([
'app_id' => $appId,
'app_secret' => $appSecret,
'default_graph_version' => 'v2.9',
]);
$oAuth2Client = $fb->getOAuth2Client();
$tokenMetaData = $oAuth2Client->debugToken($accessToken);
dump($tokenMetaData);
$graphUser = $fb->get('/me?fields=first_name,last_name,email', $accessToken)->getGraphUser()->asArray();
dump($graphUser);
上面的输出如下:
$元数据:
[
"app_id" => "..."
"application" => "My App Name"
"expires_at" => "2017-07-01 11:40:09.000000"
"is_valid" => true
"issued_at" => "2017-05-02 11:40:09.000000"
"metadata" => array:2 [
"auth_type" => "rerequest"
"sso" => "ios"
]
"scopes" => array:2 [
0 => "email"
1 => "public_profile"
]
"user_id" => "102..."
]
}
$graphUser:
array:3 [
"first_name" => "John"
"last_name" => "Smith"
"id" => "102...",
]
如您所见,$metaData
中的 scopes
显然有 email
,因此这不是权限问题。尽管如此,图形用户有时 没有电子邮件(尽管在某些情况下有)。
这是为什么,我该如何解决这个问题?
最佳答案
将您需要的字段添加到请求的 URL 中:
https://graph.facebook.com/me?fields=email,name
关于Facebook Graph API 不返回电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43737695/