EMPTY:建立沒有初始擁有者的群組。只有 Google Workspace 超級管理員或群組管理員可以使用這個值。如要進一步瞭解 Google Workspace 角色,請參閱「預先建立的管理員角色」。
Python
以下範例顯示輔助函式,可使用 Python 用戶端程式庫建立 Google 群組:
defcreate_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)exceptExceptionase:print(e)
搜尋 Google 群組
REST
如要搜尋 Google 網路論壇,請搭配查詢字串呼叫 groups.search()。如要搜尋所有群組,只需提供標籤 cloudidentity.googleapis.com/groups.discussion_forum。
Python
以下範例顯示輔助函式,可用於使用 Python 用戶端程式庫搜尋 Google 群組:
fromurllib.parseimporturlencodedefsearch_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_querysearch_group_request.uri+=paramresponse=search_group_request.execute()returnresponse
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["難以理解","hardToUnderstand","thumb-down"],["資訊或程式碼範例有誤","incorrectInformationOrSampleCode","thumb-down"],["缺少我需要的資訊/範例","missingTheInformationSamplesINeed","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-09-04 (世界標準時間)。"],[[["\u003cp\u003eThis page details the process of creating and searching for Google Groups using the Cloud Identity Groups API, highlighting the use of REST and Python client library methods.\u003c/p\u003e\n"],["\u003cp\u003eTo create a Google Group, you must use the \u003ccode\u003egroups.create()\u003c/code\u003e method, providing a \u003ccode\u003egroupKey\u003c/code\u003e, \u003ccode\u003eParent\u003c/code\u003e, and the label \u003ccode\u003ecloudidentity.googleapis.com/groups.discussion_forum\u003c/code\u003e, as well as defining an initial owner via the \u003ccode\u003einitialGroupConfig\u003c/code\u003e parameter.\u003c/p\u003e\n"],["\u003cp\u003eSearching for Google Groups involves calling the \u003ccode\u003egroups.search()\u003c/code\u003e method with a query string that includes the \u003ccode\u003ecloudidentity.googleapis.com/groups.discussion_forum\u003c/code\u003e label, and optionally a parent customer ID to filter results.\u003c/p\u003e\n"],["\u003cp\u003eBefore utilizing the Cloud Identity APIs, including the Groups API, it's crucial to complete the necessary setup steps as outlined in the "Setting up Cloud Identity" guide and the "Set up the Groups API" guide.\u003c/p\u003e\n"],["\u003cp\u003eThe customer ID format for these methods requires prepending a 'C' to the ID that is found in the Google Admin console.\u003c/p\u003e\n"]]],[],null,["# Creating and searching for Google Groups\n========================================\n\nThis page explains how to perform some fundamental operations with the\nCloud Identity Groups API.\n\nBefore you begin\n----------------\n\n| **Note:** Before you use any of the Cloud Identity APIs, you must set up Cloud Identity. See [Setting up Cloud Identity](/identity/docs/set-up-cloud-identity-admin) for instructions.\n\nPerform the following tasks before proceeding with the information on this page:\n\n- Read the [Groups API overview](/identity/docs/groups).\n\n- [Set up the Groups API](/identity/docs/how-to/setup).\n\n| **Note:** When a method requires the `customer_id`, you must prepend a \"C\" to the ID that you can view in the Google Admin console (for example, 'C046psxkn').\n\nCreating a Google Group\n-----------------------\n\n### REST\n\nTo create a Google Group, call\n[`groups.create()`](/identity/docs/reference/rest/v1/groups/create) with\nan instance of the new group. The group instance must include a `groupKey`,\n`Parent`, and `label` set to `cloudidentity.googleapis.com/groups.discussion_forum`.\n\nYou also need to set the `initialGroupConfig` parameter, which defines the\ninitial owner of the group. You can use the following values for this\nparameter:\n\n- `WITH_INITIAL_OWNER`: Makes the person sending the request the owner of the group. You should use this value in most cases.\n- `EMPTY`: Creates a group with no initial owners. You can only use this value if you're a Google Workspace Super Admin or Groups Admin. For more information about Google Workspace roles, see [Pre-built administrator\n roles](https://support.google.com/a/answer/2405986).\n\n### Python\n\nThe following example shows a helper function to create a Google Group using\nthe Python client library: \n\n def create_google_group(service, customer_id, group_id, group_display_name, group_description):\n group_key = {\"id\": group_id}\n group = {\n \"parent\": \"customers/\" + customer_id,\n \"description\": group_description,\n \"displayName\": group_display_name,\n \"groupKey\": group_key,\n # Set the label to specify creation of a Google Group.\n \"labels\": {\n \"cloudidentity.googleapis.com/groups.discussion_forum\": \"\"\n }\n }\n\n try:\n request = service.groups().create(body=group)\n request.uri += \"&initialGroupConfig=WITH_INITIAL_OWNER\"\n response = request.execute()\n print(response)\n except Exception as e:\n print(e)\n\nSearching for a Google Group\n----------------------------\n\n### REST\n\nTo search for a Google Group, call\n[`groups.search()`](/identity/docs/reference/rest/v1/groups/search) with\na query string. To search for all groups, you only need to provide the label\n`cloudidentity.googleapis.com/groups.discussion_forum`.\n\n### Python\n\nThe following example shows a helper function used to search for a Google\nGroup using the Python client library: \n\n from urllib.parse import urlencode\n\n def search_google_groups(service, customer_id):\n search_query = urlencode({\n \"query\": \"parent=='customerId/{}' && 'cloudidentity.googleapis.com/groups.discussion_forum' in labels\".format(customer_id)\n })\n search_group_request = service.groups().search()\n param = \"&\" + search_query\n search_group_request.uri += param\n response = search_group_request.execute()\n\n return response\n\nWhat's next\n-----------\n\n- After a group exists, you can create memberships for it. To create\n memberships for a Google Group, refer to\n [Managing memberships for Google Groups](/identity/docs/how-to/memberships-google-groups).\n\n- You can [update a Google Group to a security group](/identity/docs/how-to/update-group-to-security-group)."]]