【问题标题】:How to list users from Google Directory from specific domain user gmail account?如何从特定域用户 gmail 帐户列出来自 Google Directory 的用户?
【发布时间】:2017-11-09 14:16:32
【问题描述】:

我有一个使用 Google API 的许多范围的应用程序。最初它仅限于我域内的用户(我们称之为lordshark.com,它运行良好)......但现在我被要求接受任何 GMail 用户,主要问题是:

考虑到我使用某人@gmail.com 登录,我想使用 Javascript 检索 lordshark.com 域中的所有用户:

gapi.client.directory.users.list({
    'viewType': 'domain_public',
    'customer': 'my_customer',
    'maxResults': 100,
    'orderBy': 'email',
    'domain': 'lordshark.com'
})

我已授权我的 API 客户端 (https://admin.google.com/lordshark.com/AdminHome?chromeless=1#OGX:ManageOauthClients),已启用联系人共享 (https://admin.google.com/lordshark.com/AdminHome?chromeless=1#AppDetails:service=Directory&flyout=sharing) 但仍收到此响应:

{
    "error": {
        "code": 403,
        "errors": [
            {
                "domain": "global",
                "message": "Not Authorized to access this resource/api",
                "reason": "forbidden"
            }
        ],
        "message": "Not Authorized to access this resource/api"
    }
}

谁能帮我看看我错过了什么?

【问题讨论】:

    标签: javascript google-directory-api


    【解决方案1】:

    用户(不仅是客户端 ID)必须获得授权才能查看您域中的用户。通常这是由域内的管理员角色控制的。这意味着您必须以 lordshark.com 用户身份登录才能列出用户。解决此问题的唯一方法是创建一个服务帐户,如下所述: https://developers.google.com/identity/protocols/OAuth2ServiceAccount

    但这不适用于 Javascript,因此您的应用需要后端。

    【讨论】:

      猜你喜欢
      • 2017-05-31
      • 1970-01-01
      • 2014-10-12
      • 2011-07-14
      • 1970-01-01
      • 1970-01-01
      • 2012-06-16
      • 1970-01-01
      相关资源
      最近更新 更多