How to get email from facebook through Guzzle in laravel?

前端 未结 2 1419
眼角桃花
眼角桃花 2020-12-21 09:17

I am using below code to login via facebook in laravel.

Referring https://scotch.io/tutorials/token-based-authentication-for-angularjs-and-laravel-apps for token ba

相关标签:
2条回答
  • 2020-12-21 09:49

    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

    0 讨论(0)
  • 2020-12-21 09:58

    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
    ]
    ]);
    
    0 讨论(0)
提交回复
热议问题