我試圖用Outh2驗證谷歌的服務帳戶,但不斷收到此錯誤 -谷歌PHP API認證例外
異常 - 錯誤刷新的OAuth2令牌,消息:「{‘錯誤’: 「ACCESS_DENIED 「,」error_description「:」請求的客戶端不是 授權。「 }」
我已按照https://developers.google.com/api-client-library/php/auth/service-accounts 每一個指令我也沒有授權谷歌從管理控制檯中的服務帳戶,但仍然沒有運氣。任何人都可以請建議,如果在下面的代碼中有任何錯誤 -
$client_email = [email protected]';
$private_key = file_get_contents('private_key_file_location.p12');
$scopes = array('https://spreadsheets.google.com/feeds');
$user_to_impersonate = '[email protected]';
$credentials = new Google_Auth_AssertionCredentials($client_email, $scopes,
$private_key, 'notasecret',
'http://oauth.net/grant_type/jwt/1.0/bearer',
$user_to_impersonate);
$client = new Google_Client();
$client->setApplicationName('Portal Assessment Module');
$client->setAccessType('offline');
$client->setAssertionCredentials($credentials);
if ($client->getAuth()->isAccessTokenExpired()) {
$client->getAuth()->refreshTokenWithAssertion($credentials); /* Exception
is being triggered here */
}
謝謝。
感謝您的代碼,但得到它使用我發佈的答案工作 – Sandeep