【发布时间】:2016-04-16 20:42:36
【问题描述】:
我在 laravel 中使用下面的代码通过 facebook 登录。
参考https://scotch.io/tutorials/token-based-authentication-for-angularjs-and-laravel-apps 进行基于令牌的身份验证,并使用https://github.com/sahat/satellizer 进行社交媒体集成。
$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 接收电子邮件。
【问题讨论】:
-
我知道您的问题是专门询问 Guzzle,但是 Laravel Socialite 软件包可能值得一试 - 它为许多提供商(Twitter、Facebook、谷歌、Github 等)提供社交身份验证并且您可以轻松添加第三方提供商。您可能还想查看 Httpful 作为 Guzzle 的替代品 - 它有更好的文档。
-
我不同意这个评论。 Guzzle,它的文档对于 Google github.com/google/google-api-php-client、Facebook github.com/facebook/facebook-php-sdk-v4 和 Goutte github.com/FriendsOfPHP/Goutte 等公司来说似乎已经足够好了