何通过Laravel中的Guzzle从Facebook获取电子邮

何通过Laravel中的Guzzle从Facebook获取电子邮

本文介绍了如何通过Laravel中的Guzzle从Facebook获取电子邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码通过laravel中的Facebook登录.

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

引用 https://scotch.io/tutorials /token-based-authentication-for-angularjs-and-laravel-apps 进行基于令牌的身份验证,并使用 https ://github.com/sahat/satellizer 用于社交媒体集成.

Referring https://scotch.io/tutorials/token-based-authentication-for-angularjs-and-laravel-apps for token based authentication and using https://github.com/sahat/satellizer for social media integration.

$params = [
        'code' => $request->input('code'),
        'client_id' => $request->input('clientId'),
        'redirect_uri' => $request->input('redirectUri'),
        'client_secret' => 'XXXXXXXXXXXXXXXXXXX'
        /*'client_secret' => Config::get('app.facebook_secret')*/
    ];

    // Step 1. Exchange authorization code for access token.
    $accessTokenResponse = $client->request('GET', 'https://graph.facebook.com/v2.5/oauth/access_token', [
        'query' => $params
    ]);
    $accessToken = json_decode($accessTokenResponse->getBody(), true);

    // Step 2. Retrieve profile information about the current user.
    $profileResponse = $client->request('GET', 'https://graph.facebook.com/v2.5/me', [
        'query' => $accessToken
    ]);
    $profile = json_decode($profileResponse->getBody(), true);

$ profile仅返回fb ID和用户名.我应该做些什么改变才能收到来自Facebook的电子邮件.

$profile returning only fb id and user name.What changes should I do to get email from facebook.

推荐答案

在第2步中使用以下代码.

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

这篇关于如何通过Laravel中的Guzzle从Facebook获取电子邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 05:04