Php 未捕获异常';apiAuthException';带有消息';获取OAuth2访问令牌时出错,消息:';无效的授权'';

Php 未捕获异常';apiAuthException';带有消息';获取OAuth2访问令牌时出错,消息:';无效的授权'';,php,google-oauth,Php,Google Oauth,我正在使用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('

我正在使用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''

我看了很多答案,但没有找到答案,有人能具体说出问题出在哪里吗?

我找到了答案。我使用的API本身就有问题。所以,我在谷歌上搜索了更多,找到了可用的APi。 下面是任何人想要的链接

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