【发布时间】:2013-10-01 09:03:08
【问题描述】:
我明白了
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 APIs 控制台 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”消息。有什么想法吗?
【问题讨论】:
-
嘿,史蒂夫,你最终在 PHP 中得到了这个工作吗?
-
没有。我决定等到谷歌完成他们的控制台更新。他们的文档全都一团糟:你绕着圈子点击指向当前文档的链接,但最后却是过时的文档。我已经看到了用于设置服务帐户的三种不同用户界面。我想我只需要等到他们把它整理好。
-
gotchya,感谢您的回复。
标签: php google-api google-apps