【发布时间】:2014-04-24 15:09:32
【问题描述】:
我在 Google API 控制台中有一个 APP。它启用了 Admin SDK 和 Marketplace SDK。我已将其注册为服务帐户,并且拥有密钥文件等。当我尝试从某个域获取用户时,它总是向我显示一条消息-“调用 GET https://www.googleapis.com/admin/directory/v1/users?domain=mydomain.com 时出错:(403)未授权访问此资源/api”。我的代码是这样的:
$client = new Google_Client();
$client->setApplicationName("Client_User_Feed");
$key = file_get_contents('/path/to/key/key-file-privatekey.p12');
$cred = new Google_Auth_AssertionCredentials(
'{code}@developer.gserviceaccount.com',
array('https://www.googleapis.com/auth/admin.directory.user'),
$key
);
$client->setAssertionCredentials($cred);
$service = new Google_Service_Directory($client);
$users = $service->users->listUsers(array('domain' => 'mydomain.com'));
我该如何解决这个问题?
【问题讨论】:
-
您是否在域管理控制台中添加了应用范围?
-
我在 Marketplace SDK 管理员中有这个范围 - ttps://www.googleapis.com/auth/admin.directory.user
标签: google-app-engine google-api