我正在尝试使用 Satellizer 和angularjs 作为前端,使用 laravel & Guzzle 6 作为后端的社交验证教程。我在使用 Guzzle 查询用户个人资料信息时遇到问题:这是我的控制器中的 php 代码:
$accessTokenUrl = 'https://accounts.google.com/o/oauth2/token';
$peopleApiUrl = 'https://www.googleapis.com/plus/v1/people/me/openIdConnect';
$params = [
'code' => $request->input('code'),
'client_id' => $request->input('clientId'),
'client_secret' => 'my-client-secret',
'redirect_uri' => $request->input('redirectUri'),
'grant_type' => 'authorization_code',
];
$client = new GuzzleHttp\Client();
$accessTokenResponse = $client->post($accessTokenUrl, ['form_params' => $params]);
$accessToken = json_decode($accessTokenResponse->getBody()->getContents(),true)['access_token'];
try {
// $profileResponse = $client->get($peopleApiUrl, ['header' => ['Authorization' => 'Bearer ' . $accessToken,]]); -->not working
$profileResponse = $client->get($peopleApiUrl,['oauth_token'=>$accessToken]);
} catch (RequestException $e) {
return response()->json($e);
}
我无法连接以获取用户配置文件和错误消息:
ClientException in Middleware.php line 69: Client error: 403
in Middleware.php line 69
at Middleware::GuzzleHttp\{closure}(object(Response)) in Promise.php line 199
at Promise::callHandler('1', object(Response), array(object(Promise), object(Closure), null)) in Promise.php line 152
at Promise::GuzzleHttp\Promise\{closure}() in TaskQueue.php line 60
at TaskQueue->run() in CurlMultiHandler.php line 96
at CurlMultiHandler->tick() in CurlMultiHandler.php line 123
at CurlMultiHandler->execute(true) in Promise.php line 240
at Promise->invokeWaitFn() in Promise.php line 217
at Promise->waitIfPending() in Promise.php line 261
at Promise->invokeWaitList() in Promise.php line 219
at Promise->waitIfPending() in Promise.php line 62
.......
有人有同样的问题并找到解决方法吗?请帮忙。谢谢。