【问题标题】:Google Directory API groupsGoogle 目录 API 组
【发布时间】:2014-07-02 21:08:47
【问题描述】:

我正在尝试使用 Google 的管理目录 API(使用 Google 的 python 库)。

我可以很好地列出目录中的用户,使用如下代码:

results = client.users().list(customer='my_customer').execute()

但是,这些结果不包括用户所属的组。相反,一旦我有了用户列表,我就必须打电话来获取组列表:

results = client.groups().list(customer='my_customer').execute()

然后遍历每个组,调用“members” api查看组中有哪些用户:

results = client.members().list(groupKey='[group key]').execute()

这意味着我必须为每个组提出新的请求。

这似乎非常低效。必须有比这更好的方法,而我只是想念它。这是什么?

【问题讨论】:

    标签: python google-api google-directory-api


    【解决方案1】:

    没有比您描述的更好的方法(还没有?):遍历组并获取每个组的成员列表。

    我同意这不是您想要阅读的答案,但这也是我们对组成员进行维护的方式。

    【讨论】:

      【解决方案2】:

      以下方法应该更有效,虽然不是 100% 好:

      对于每个用户,调用the groups.list method 并传递userKey 参数以指定您只需要拥有用户X 作为成员的组。

      我不是 Python 开发人员,但它应该是这样的:

      results = client.groups().list(customer='my_customer',userKey='user@domain.com').execute()
      

      【讨论】:

      • 实际上这似乎效率较低,因为用户肯定多于组。查询每个用户的组列表将比查询每个组的成员列表更多的 API 请求。
      • 我不认为 client.groups().list() 需要 2 个参数。
      【解决方案3】:

      对于每个用户:

      结果 = client.groups().list(userKey=user,pageToken=None).execute()

      其中“用户”是用户的主要/别名电子邮件地址或 ID

      这将返回用户所属的组页面,请参阅:

      https://developers.google.com/admin-sdk/directory/v1/reference/groups/list

      【讨论】:

      • 查看我对@David 回答的评论。
      猜你喜欢
      • 1970-01-01
      • 2013-09-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-04
      • 2020-07-31
      相关资源
      最近更新 更多