【发布时间】:2015-09-01 22:35:00
【问题描述】:
我正在尝试使用 Admin SDK PHP 库列出我的 google 域中的用户。但是,当我尝试列出我的用户时,我得到了 403 个用户。这是我试过的
$client = new Google_Client();
$client->setApplicationName("My Application");
$credential = new Google_Auth_AssertionCredentials(
$serviceAccount,
array('https://www.googleapis.com/auth/admin.directory.user'),
$privateKey,
'notasecret',
'http://oauth.net/grant_type/jwt/1.0/bearer'
);
$client->setAssertionCredentials($credential);
if($client->getAuth()->isAccessTokenExpired())
{
$client->getAuth()->refreshTokenWithAssertion($credential);
}
$service = new Google_Service_Directory($client);
$optParams = array('domain' => 'mydomain');
$results = $service->users->listUsers($optParams);
但是我收到了这个 403 错误
Error calling GET https://www.googleapis.com/admin/directory/v1/users?domain=mydomain: (403) Not Authorized to access this resource/api
正如其他类似帖子中所建议的那样,我也尝试包括如下所示的委派管理员
$credential = new Google_Auth_AssertionCredentials(
$serviceAccount,,
array('https://www.googleapis.com/auth/admin.directory.user'),
$privateKey,
'notasecret',
'http://oauth.net/grant_type/jwt/1.0/bearer',
'admin@mydomain.com'
);
但这在 refreshTokenWithAssertion($credential) 上给出了以下错误
Error refreshing the OAuth2 token, message: '{
"error" : "unauthorized_client",
"error_description" : "Unauthorized client or scope in request."
}'
我验证了服务帐户并在项目的控制台中启用了 API。谁能弄清楚我做错了什么?请帮忙。我在这方面有一段时间了。
【问题讨论】:
标签: php google-api google-api-php-client google-admin-sdk