【问题标题】:Python Retrieving all Groups from a domain using OAuth2Python使用OAuth2从域中检索所有组
【发布时间】:2015-03-13 21:59:10
【问题描述】:

使用 PYTHON,要获取域中的所有组,在 OAuth1 中有如下命令:

groupfeed = api(lambda: GROUPS_SERVICE.RetrieveAllGroups()) 

在OAuth2中,会不会是

allGrps = client.groups().list(customer='my_company').execute()

我正在寻找等效代码来获取域中的所有组。感谢您的帮助和关注。

【问题讨论】:

    标签: google-groups google-groups-api google-groups-migration


    【解决方案1】:

    如果您有超过 200 个组,结果将被分页并通过多个 API 调用返回。您需要不断检索页面,直到没有页面为止:

    all_groups = []
    request = client.groups().list(customer='my_customer')
    while True: # loop until no nextPageToken
      this_page = request.execute()
      if 'items' in this_page:
        all_groups += this_page['items']
      if 'nextPageToken' in this_page:
        request = client.groups().list(
          customer='my_customer',
          pageToken=this_page['nextPageToken'])
      else:
        break
    

    还要注意它是 my_customer,而不是 my_company。

    【讨论】:

    • 谢谢杰。欣赏它,会试试这个。
    • 我只对此列表中的组名感兴趣。如何只检索组?
    • @user1816974 组名是items 中字典的一部分。只需执行all_groups += [item['name'] for item in items]。见developers.google.com/admin-sdk/directory/v1/guides/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-24
    • 2014-08-20
    • 2015-07-31
    • 1970-01-01
    • 2016-11-03
    相关资源
    最近更新 更多