![](/img/trans.png)
[英]Uncaught Google_Auth_Exception: Error fetching OAuth2 access token, message: 'invalid_client: Unauthorized'
[英]Fatal error: Uncaught exception 'Google_Auth_Exception' with message 'Error fetching OAuth2 access token, message: 'invalid_client''
我正在開發帶有googleplus登錄名的移動應用程序。 我在哪里獲取訪問令牌並將其發送到我的服務器,以便使用適用於PHP的Google API客戶端庫進行驗證。
當我嘗試驗證令牌時,出現致命錯誤消息:
Fatal error: Uncaught exception 'Google_Auth_Exception' with message 'Error fetching OAuth2 access token, message: 'invalid_client'' in C:\xxx\vendor\google\apiclient\src\Google\Auth\OAuth2.php:127 Stack trace: #0 C:\xxx\vendor\google\apiclient\src\Google\Client.php(130): Google_Auth_OAuth2->authenticate('ya29.2QBihTdAag...') #1 C:\xxx\index.php(20): Google_Client->authenticate('ya29.2QBihTdAag...') #2 {main} thrown in C:\xxx\vendor\google\apiclient\src\Google\Auth\OAuth2.php on line 127
這是我的PHP代碼:
<?php
$google_client_id = 'XXXXX.apps.googleusercontent.com';
$google_client_secret = 'XXXXX';
$google_redirect_url = 'xxx';
$google_developer_key = 'XXXXXXXX';
$google_application_name = 'XXXX Login';
$google_application_scope = 'email'; /* I only needed the basic user info */
$google_redirect_uri='';
//include google api files
require_once 'vendor/autoload.php';
$gClient = new Google_Client();
$gClient->setApplicationName($google_application_name);
$gClient->setClientId($google_client_id);
$gClient->setClientSecret($google_client_secret);
$gClient->setRedirectUri($google_redirect_uri);
$gClient->setScopes($google_application_scope);
$gClient->setDeveloperKey($google_developer_key);
$gClient->authenticate("ya29.2QBihTdAagwpH5hHJUg5soIETLspVUgle6VPOT52UYPWkOKyHdUJlpUyvoMKPgkuqIS4PvgXQhfpHw");//Error Happened here
$token = json_decode($gClient->getAccessToken());
$google_oauthV2 = new Google_Service_Oauth2($gClient);
$user_info = $google_oauthV2->userinfo->get();
var_dump(user_info);
die();
?>
對於$google_client_secret
代替, 'notasecret'
中使用值"CLIENT SECRET"
的部分"Client ID for web application"
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.