Facebook Graph API不返回电子邮件 [英] Facebook Graph API not returning email

查看:121
本文介绍了Facebook Graph API不返回电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码:

$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);

以上内容的输出如下:

$ metaData :

 [
   "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,因此这不是权限问题.尽管如此,图形用户有时仍然没有电子邮件(尽管在某些情况下确实如此).

As you can see, the scopes in $metaData clearly has email so it isn't a permission issue. Despite this, the graph user sometimes does not have the email (although in some cases it does).

这是为什么,我该如何解决这个问题?

Why is this and how can I solve this issue?

推荐答案

将所需的字段添加到请求的URL:

Add the fields you need to the URL of your request:

https://graph.facebook.com/me?fields=email,name

这篇关于Facebook Graph API不返回电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆