user1816974
user1816974

Reputation: 29

Python Retrieving all Groups from a domain using OAuth2

Using PYTHON, To get all groups in a domain, in OAuth1 had a command like:

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

In OAuth2, will it be

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

I am looking for the equivalent code to get ALL groups in a domain. Thanks for your help and attention.

Upvotes: 0

Views: 590

Answers (1)

Jay Lee
Jay Lee

Reputation: 13528

If you have more than 200 groups, the results will be paged and returned over multiple API calls. You need to keep retrieving pages until none are left:

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

also notice that it's my_customer, not my_company.

Upvotes: 0

Related Questions