我越来越
Error calling GET https://www.googleapis.com/admin/directory/v1/users/email@example.com.com: (403) Not Authorized to access this resource/api
跑步时
$client = new Google_Client();
$client->setClientId(GOOGLEAPPS_CLIENT_ID);
$client->setApplicationName(SITE_NAME);
$key = file_get_contents(APPLICATION_PATH . 'googleapps-privatekey.p12');
$assertion = new Google_AssertionCredentials(
GOOGLEAPPS_EMAIL_ADDRESS, // the service account name
array('https://www.googleapis.com/auth/admin.directory.user'), // see https://developers.google.com/admin-sdk/directory/v1/guides/authorizing
$key);
$client->setAssertionCredentials($assertion);
$service = new Google_DirectoryService($client);
$user = $service->users->get('email@example.com');
我按照说明https://developers.google.com/admin-sdk/directory/v1/guides/prerequisites 并勾选启用 API 访问。我使用 Google API 控制台https://code.google.com/apis/console生成服务帐户密钥并使其正常工作。
https://groups.google.com/forum/#!msg/google-api-php-client/LM-mwmuZe7I/IA_K5v1R1UMJ
我使用了 Google PHP 库并按照说明https://code.google.com/p/google-api-php-client/wiki/OAuth2?hl=no#Service_Accounts尝试让服务帐户正常工作。调试他们的代码:我正在授权并按预期获得一个新的访问令牌https://developers.google.com/accounts/docs/OAuth2ServiceAccount。
当我读到的所有内容都表明我已将其全部打开时,我无法弄清楚为什么我会收到“未授权访问此资源/api”消息。有任何想法吗?