0
我试图按照教程here 使用Satellizer和angularjs作为前端和laravel & Guzzle 6为后端与社会认证。我用狂饮查询用户资料信息有问题:这是我的PHP代码在我的控制器:谷歌OAuth无法正常工作。
$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
.......
人有同样的问题并找到一种方法来解决它?请帮忙。 谢谢。
你的痕迹会变回吗?您的代码是否会在第一个请求(身份验证)或第二个请求(API访问)上“崩溃”?将客户端置于“调试”模式时会发生什么? –
谢谢肖恩。我改变了链接(波纹管答案),现在它可以工作。 – user804293