Google グループの作成と検索

このページでは、Cloud Identity Groups API を使用して基本的なオペレーションを行う方法について説明します。

始める前に

次の作業を実施した後、このページの内容に進んでください。

Google グループを作成する

REST

Google グループを作成するには、groups.create() を呼び出して新しいグループのインスタンスを指定します。グループ インスタンスには、cloudidentity.googleapis.com/groups.discussion_forum に設定された groupKeyParentlabel を含める必要があります。

また、initialGroupConfig パラメータも設定する必要があります。このパラメータは、グループの初期オーナーを定義します。このパラメータには、次の値を使用できます。

  • WITH_INITIAL_OWNER: リクエストを送信したユーザーをグループのオーナーにします。ほとんどの場合、この値を使用する必要があります。
  • EMPTY: 初期オーナーを持たないグループを作成します。この値は、Google Workspace 特権管理者またはグループ管理者のみが使用できます。Google Workspace のロールの詳細については、既定の管理者ロールをご覧ください。

Python

Python クライアント ライブラリを使用して Google グループを作成するヘルパー関数を、次の例に示します。

def create_google_group(service, customer_id, group_id, group_display_name, group_description):
  group_key = {"id": group_id}
  group = {
    "parent": "customers/" + customer_id,
    "description": group_description,
    "displayName": group_display_name,
    "groupKey": group_key,
    # Set the label to specify creation of a Google Group.
    "labels": {
      "cloudidentity.googleapis.com/groups.discussion_forum": ""
    }
  }

  try:
    request = service.groups().create(body=group)
    request.uri += "&initialGroupConfig=WITH_INITIAL_OWNER"
    response = request.execute()
    print(response)
  except Exception as e:
    print(e)

Google グループを検索する

REST

Google グループを検索するには、groups.search() を呼び出してクエリ文字列を指定します。ラベル cloudidentity.googleapis.com/groups.discussion_forum を指定すれば、すべてのグループを検索できます。

Python

Python クライアント ライブラリを使用して Google グループを検索するために使用されるヘルパー関数を、次の例に示します。

from urllib.parse import urlencode

def search_google_groups(service, customer_id):
  search_query = urlencode({
          "query": "parent=='customerId/{}' && 'cloudidentity.googleapis.com/groups.discussion_forum' in labels".format(customer_id)
  })
  search_group_request = service.groups().search()
  param = "&" + search_query
  search_group_request.uri += param
  response = search_group_request.execute()

  return response

次のステップ