Google管理员SDK目录API用户权限

时间:2014-01-09 04:51:06

标签: google-oauth google-admin-sdk google-api-php-client

我的域中的普通用户帐户是否可以访问Google OAuth2目录服务API上的功能来检索用户列表或数据?

我有一个网络应用程序,允许用户使用OAuth2.0登录。之后,用户应该能够看到他们的个人资料数据。

如果我使用超级管理员登录,一切正常,数据显示。当我使用普通用户登录和组管理员登录时,我看不到任何数据并收到如下错误消息:

    Fatal error: Uncaught exception 'Google_ServiceException' with message 'Error calling GET https://www.googleapis.com/admin/directory/v1/users/yifei.liu@example.com?key=(MY_API_Key): (403) Not Authorized to access this resource/api' in /home2/iaapro/public_html/php/google-api-php-client/src/io/Google_REST.php:66 Stack trace: #0 /home2/iaapro/public_html/php/google-api-php-client/src/io/Google_REST.php(36): Google_REST::decodeHttpResponse(Object(Google_HttpRequest)) 
#1 /home2/iaapro/public_html/php/google-api-php-client/src/service/Google_ServiceResource.php(186): Google_REST::execute(Object(Google_HttpRequest)) 
#2 /home2/iaapro/public_html/php/google-api-php-client/src/contrib/Google_DirectoryService.php(653): Google_ServiceResource->__call('get', Array) 
#3 /home2/iaapro/public_html/php/google-plus-access.php(47): Google_UsersServiceResource->get('yifei.liu@iaapr...') 
#4 /home2/iaapro/public_html/php/index.php(2): include_once('/home2/iaapro/p...') 
#5 {main} thrown in /home2/iaapro/public_html/php/google-api-php-client/src/io/Google_REST.php on line 66

这是否意味着只有具有域超级管理员权限的帐户才能访问Google Admin SDK目录API?我是否可以允许普通用户使用此API?

感谢。

2 个答案:

答案 0 :(得分:1)

是。普通用户可以以只读模式检索域的目录联系人。他们无法对目录中的任何内容进行更改

要列出目录联系人,您需要

$client->addScope("https://www.googleapis.com/auth/admin.directory.user.readonly");

在你的oauth流程中。

然后检索,做这样的事情:

$service = new Google_Service_Directory($client);
$optParams = array(
        'domain' => 'google.domain.com',
        'orderBy' => 'email',
        'viewType' => 'domain_public',
        'query' => "givenName:'Joe' familyName:'Schmoe Jr'"
);
$results = $service->users->listUsers($optParams);
$users = $results->getUsers();

您也可以通过服务帐户完成此操作,在这种情况下,您的用户永远不需要完成oauth步骤。请参阅此处查看工作示例:Google php client library loadServiceAccountJson broken - fix enclosed

答案 1 :(得分:0)

没有。 “普通”用户无法管理您网域的用户。例如,只有管理员帐户可以创建,删除或更新信息。关于用户。

请查看Admin SDK page如果您想管理联系人

“普通”用户可以管理他/她的联系人。他们可以看到电子邮件,电话号码,标签等等。

您可以访问Google contacts API V3访问以获取更多相关信息。

相关问题