Google Admin SDK Directory API User Privileges



我的域中的普通用户帐户可以访问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 管理员 SDK 目录 API?我也可以允许普通用户使用此 API 吗?

谢谢。

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

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

$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 客户端库加载ServiceAccountJson 已损坏 - 修复封闭

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

如果您想管理联系人,请查看管理员 SDK 页面

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

您可以访问访问 谷歌联系人API V3 以获取更多信息。

最新更新