簡體   English   中英

消息“獲取OAuth2訪問令牌時出錯,消息:'invalid_grant”的未捕獲異常'apiAuthException'

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM