我正在使用https://github.com/sahat/satellizer在我的 angular + laravel ( 5.2 ) 应用程序中添加带有 facebook 功能的登录。
这是我在 php 中用来调用 facebook graph api 的代码
$client = new GuzzleHttp\Client();
$params = [
'code' => $request->input('code'),
'client_id' => $request->input('clientId'),
'redirect_uri' => $request->input('redirectUri'),
'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);
但它只是在响应中返回 id 和 name。我尝试将 id、name 和 email 作为 url 中的字段添加为
$profileResponse = $client->request('GET', 'https://graph.facebook.com/v2.5/me?fields=id,name,email', [
'query' => $accessToken
]);
它仍然只返回 id 和 name。
我还在 Graph API Explorer 中使用上述请求返回的令牌进行了尝试。它显示了适当的反应。
谢谢