![](/img/trans.png)
[英]Google_Auth_Exception' with message 'Error fetching OAuth2 access token, message: 'invalid_grant'
[英]Uncaught exception 'apiAuthException' with message 'Error fetching OAuth2 access token, message: 'invalid_grant''
我使用的是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本身有問題。 所以,我在Google上搜索了更多,發現可以使用APi。 以下是任何人想要的鏈接
http://www.sanwebe.com/2012/11/login-with-google-api-php
謝謝 :)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.