defcreate_identity_group_membership(service,identity_source_id,group_id,member_key):param="&groupKey.id="+group_id+"&groupKey.namespace=identitysources/"+identity_source_idtry:lookupGroupNameRequest=service.groups().lookup()lookupGroupNameRequest.uri+=paramlookupGroupNameResponse=lookupGroupNameRequest.execute()groupName=lookupGroupNameResponse.get("name")membership={"memberKey":member_key,"roles":{"name":"MEMBER"}}# Create a membership using the ID for the parent group and a membership objectresponse=service.groups().memberships().create(parent=groupName,body=membership).execute()printresponseexceptException,e:printe
deflist_identity_group_membership(service,identity_source_id,group_id):param="&groupKey.id="+group_id+"&groupKey.namespace=identitysources/"+identity_source_idtry:lookup_group_name_request=service.groups().lookup()lookup_group_name_request.uri+=paramlookup_group_name_response=lookup_group_name_request.execute()group_name=lookup_group_name_response.get("name")# List membershipsresponse=service.groups().memberships().list(parent=group_name).execute()printresponseexceptException,e:printe
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-08-18。"],[[["\u003cp\u003eThis page outlines how to manage memberships within identity-mapped groups using the Cloud Identity Groups API.\u003c/p\u003e\n"],["\u003cp\u003eYou can add a member to an identity-mapped group by utilizing the \u003ccode\u003egroups.memberships.create()\u003c/code\u003e method, providing the parent group's ID and a membership resource.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003egroups.memberships.list()\u003c/code\u003e method, along with the parent group's ID, enables you to retrieve a list of memberships for a specific identity-mapped group.\u003c/p\u003e\n"],["\u003cp\u003eThe provided Python code snippets demonstrate how to add a member to a group and how to list all members of a group with their respective methods.\u003c/p\u003e\n"]]],[],null,["# Managing identity-mapped group memberships\n==========================================\n\nAfter a group exists, you can create memberships for it. This page explains\nhow to perform some fundamental membership operations with the\nCloud Identity Groups API.\n| **Note:** To learn how to create an identity-mapped group, refer to [Creating and searching for identity groups](/identity/docs/how-to/create-identity-groups).\n\nBefore you begin\n----------------\n\nSet up authentication and install the client libraries. See\n[Setting up the Cloud Identity Groups API](/identity/docs/how-to/setup) to learn how.\n\nAdding a membership to an identity-mapped group\n-----------------------------------------------\n\n### REST\n\nTo add a member to an identity-mapped group, call\n[`groups.memberships.create()`](/identity/docs/reference/rest/v1/groups.memberships/create)\nwith the ID of the parent group and a\n[memberships](/identity/docs/reference/rest/v1/groups.memberships)\nresource.\n\n### Python\n\nThe following code shows you how to associate a member with a group: \n\n def create_identity_group_membership(service, identity_source_id, group_id, member_key):\n param = \"&groupKey.id=\" + group_id + \"&groupKey.namespace=identitysources/\" + identity_source_id\n try:\n lookupGroupNameRequest = service.groups().lookup()\n lookupGroupNameRequest.uri += param\n lookupGroupNameResponse = lookupGroupNameRequest.execute()\n groupName = lookupGroupNameResponse.get(\"name\")\n membership = {\n \"memberKey\": member_key,\n \"roles\" : {\n \"name\" : \"MEMBER\"\n }\n }\n # Create a membership using the ID for the parent group and a membership object\n response = service.groups().memberships().create(parent=groupName, body=membership).execute()\n print response\n except Exception, e:\n print e\n\nListing memberships for an identity-mapped group\n------------------------------------------------\n\n### REST\n\nTo list memberships in an identity-mapped group, call\n[`groups.memberships.list()`](/identity/docs/reference/rest/v1/groups.memberships/list)\nwith the ID of the parent group and a\n[memberships](/identity/docs/reference/rest/v1/groups.memberships)\nresource.\n\n### Python\n\nThe following code lists the memberships for a group: \n\n def list_identity_group_membership(service, identity_source_id, group_id):\n param = \"&groupKey.id=\" + group_id + \"&groupKey.namespace=identitysources/\" + identity_source_id\n try:\n lookup_group_name_request = service.groups().lookup()\n lookup_group_name_request.uri += param\n lookup_group_name_response = lookup_group_name_request.execute()\n group_name = lookup_group_name_response.get(\"name\")\n # List memberships\n response = service.groups().memberships().list(parent=group_name).execute()\n print response\n except Exception, e:\n print e"]]