【问题标题】:Uncaught exception 'apiAuthException' with message 'Error fetching OAuth2 access token, message: 'invalid_grant''未捕获的异常 'apiAuthException' 带有消息'获取 OAuth2 访问令牌时出错,消息:'invalid_grant''
【发布时间】:2014-10-18 19:29:01
【问题描述】:

我正在使用 Google OAuth2 脚本让用户使用他的 google+ 帐户登录。以下是获取访问令牌的代码:

require_once 'src/apiClient.php';
require_once 'src/contrib/apiPlusService.php';
$client = new apiClient();
$client->setApplicationName("Google+ Login Application");
$client->setScopes(array('https://www.googleapis.com/auth/plus.me'));
$plus = new apiPlusService($client);
if (isset($_GET['code'])) {
  $client->authenticate();
  $_SESSION['access_token'] = $client->getAccessToken();
  header('Location: http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']);
 }

config.php 中,我将客户端 ID 和密码设置如下:

 'oauth2_client_id' => 'XYZ',
'oauth2_client_secret' => 'ABC',
'oauth2_redirect_uri' => 'http://example.com/gplus/index',

当我通过 google+ 帐户登录然后在重定向时,我得到以下异常:

Uncaught exception 'apiAuthException' with message 'Error fetching OAuth2 
access token, message: 'invalid_grant''

看了很多答案,都没有找到解决办法,能不能具体说说问题出在哪里?

【问题讨论】:

    标签: php google-oauth


    【解决方案1】:

    我想通了。我使用的API,本身就有问题。所以,我用谷歌搜索了更多,找到了工作的 APi。 如果有人想要,下面是链接

    http://www.sanwebe.com/2012/11/login-with-google-api-php
    

    谢谢:)

    【讨论】:

      猜你喜欢
      • 2014-11-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-04
      • 1970-01-01
      相关资源
      最近更新 更多