How to get email from facebook through Guzzle in laravel?

五迷三道 提交于 2019-11-29 16:09:53

Use below code in your step 2.

$fields = 'id,email,first_name,last_name,link,name';
$profileResponse = $client->request('GET', 'https://graph.facebook.com/v2.5/me', [
'query' => [
    'access_token' => $accessToken['access_token'],
    'fields' => $fields
]
]);

Replace this:

'https://graph.facebook.com/v2.5/me'

with this:

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

It´s called "Declarative Fields", see changelog.

Also, you need to authorize with the email permission, of course. And the email has to be confirmed. You can´t be 100% sure to get an email, some users use their phone number to login.

You should also check this out: https://github.com/sahat/satellizer/issues/615

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!