【发布时间】:2015-06-09 05:59:08
【问题描述】:
我正在尝试使用 Outh2 验证 google 服务帐户,但不断收到此错误 -
异常 - 刷新 OAuth2 令牌时出错,消息:'{ "error" : "access_denied", "error_description" : "请求的客户端不 授权。”}'
我已按照https://developers.google.com/api-client-library/php/auth/service-accounts 的所有指示进行操作 我也确实从谷歌管理控制台授权了服务帐户,但仍然没有运气。任何人都可以建议下面的代码是否有任何问题-
$client_email = aab123@developer.gserviceaccount.com';
$private_key = file_get_contents('private_key_file_location.p12');
$scopes = array('https://spreadsheets.google.com/feeds');
$user_to_impersonate = 'user@example.com';
$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 */
}
谢谢。
【问题讨论】: