我试图用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