谷歌OAuth不工作


Guzzle 6 with google OAuth not working.?

我正在尝试遵循这里的教程使用Satellizer和angularjs作为前端和后台;为后端提供社交身份验证。我有问题使用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
.......

有人有同样的问题,并找到了一个方法来解决它?请帮助。谢谢。

对于任何有同样问题的人,都可以尝试遵循Satellizer的例子,用于Laravel和php。我改变谷歌API url(从文档),现在我可以得到用户配置文件信息。

$peopleApiUrl = 'https://www.googleapis.com/oauth2/v3/userinfo';  // works with this link

示例中的链接可能适用于旧版本。