Retrieving a dynamic group and listing members

You can retrieve dynamic groups by name or email. After you retrieve a group, you can list its memberships.

Retrieving a dynamic group by name

The following sample shows how to retrieve a dynamic group by name:

REST

To retrieve a dynamic group by name, call groups.get() with the resource name of the group.

Python

The following example shows how to retrieve a dynamic group by name using the python library:

def get_dynamic_group_by_name(name):
  service = build_service()
  response = service.groups().get(name=name).execute()
  return response

Retrieving a dynamic group by email

The following sample shows how to retrieve a dynamic group by email:

REST

To retrieve a dynamic group by email, call groups.get() with the group email address.

Python

The following example shows how to retrieve a dynamic group by email using the python library:

def get_dynamic_group_by_email(email):
  service = build_service()

  # First we use the email to get the groups name calling lookup()
  lookup_group_name_request = service.groups().lookup()
  param = "&groupKey.id=" + email
  lookup_group_name_request.uri += param
  lookup_group_name_response = lookup_group_name_request.execute()
  name = lookup_group_name_response.get("name")

  # Then we can call get() by passing in the group's name
  response = service.groups().get(name=name).execute()
  return response

Listing memberships of a dynamic group

The following sample shows how to list the memberships of a dynamic group:

REST

To list memberships of a group, call groups.memberships.get() with the resource name of the group.

Python

The following example shows how to list memberships of a dynamic group using the python library:

def get_dynamic_group_memberships(name):
  service = build_service()

  members_request = service.groups().memberships().list(parent=name)
  members_request.uri += "&view=FULL"
  response = members_request.execute()
  return response