【发布时间】: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