Get details about a membership (original) (raw)
- This guide explains how to use the
get()method to retrieve details about a membership in a Google Chat space. - Google Workspace administrators can use the
get()method with administrator privileges to retrieve membership details for any user in their organization. - To get membership details, you need to authenticate using either app authentication or user authentication with the appropriate authorization scopes.
- You need to provide the
nameof the membership, which includes the space ID and member ID, to theget()method. - The
get()method returns aMembershipobject containing details about the specified membership.
This guide explains how to use theget()method on the Membership resource of the Google Chat API to get details about a membership in a space.
If you're a Google Workspace administrator, you can call the get() method to retrieve details about any membership in your Google Workspace organization.
TheMembership resourcerepresents whether a human user or Google Chat app is invited to, part of, or absent from a space.
Authenticating withapp authenticationlets a Chat app get memberships from spaces that it has access to in Google Chat (for example, spaces it's a member of), but excludes Chat app memberships, including its own. Authenticating withuser authenticationreturns memberships from spaces that the authenticated user has access to.
Prerequisites
Node.js
- A Business or EnterpriseGoogle Workspace account with access toGoogle Chat.
- Set up your environment:
- Create a Google Cloud project.
- Configure the OAuth consent screen.
- Enable and configure the Google Chat API with a name, icon, and description for your Chat app.
- Install the Node.js Cloud Client Library.
- Create access credentials based on how you want to authenticate in your Google Chat API request:
* To authenticate as a Chat user,create OAuth client ID credentials and save the credentials as a JSON file namedcredentials.jsonto your local directory.
* To authenticate as the Chat app,create service account credentials and save the credentials as a JSON file namedcredentials.json.
- Choose an authorization scope based on whether you want to authenticate as a user or the Chat app.
- A Google Chat space where the authenticated user or calling Chat app is a member. To authenticate as the Chat app, add the Chat app to the space.
Python
- A Business or EnterpriseGoogle Workspace account with access toGoogle Chat.
- Set up your environment:
- Create a Google Cloud project.
- Configure the OAuth consent screen.
- Enable and configure the Google Chat API with a name, icon, and description for your Chat app.
- Install the Python Cloud Client Library.
- Create access credentials based on how you want to authenticate in your Google Chat API request:
* To authenticate as a Chat user,create OAuth client ID credentials and save the credentials as a JSON file namedcredentials.jsonto your local directory.
* To authenticate as the Chat app,create service account credentials and save the credentials as a JSON file namedcredentials.json.
- Choose an authorization scope based on whether you want to authenticate as a user or the Chat app.
- A Google Chat space where the authenticated user or calling Chat app is a member. To authenticate as the Chat app, add the Chat app to the space.
Java
- A Business or EnterpriseGoogle Workspace account with access toGoogle Chat.
- Set up your environment:
- Create a Google Cloud project.
- Configure the OAuth consent screen.
- Enable and configure the Google Chat API with a name, icon, and description for your Chat app.
- Install the Java Cloud Client Library.
- Create access credentials based on how you want to authenticate in your Google Chat API request:
* To authenticate as a Chat user,create OAuth client ID credentials and save the credentials as a JSON file namedcredentials.jsonto your local directory.
* To authenticate as the Chat app,create service account credentials and save the credentials as a JSON file namedcredentials.json.
- Choose an authorization scope based on whether you want to authenticate as a user or the Chat app.
- A Google Chat space where the authenticated user or calling Chat app is a member. To authenticate as the Chat app, add the Chat app to the space.
Apps Script
- A Business or EnterpriseGoogle Workspace account with access toGoogle Chat.
- Set up your environment:
- Create a Google Cloud project.
- Configure the OAuth consent screen.
- Enable and configure the Google Chat API with a name, icon, and description for your Chat app.
- Create a standalone Apps Script project, and turn on the Advanced Chat Service.
- In this guide, you must use either user or app authentication. To authenticate as the Chat app, create service account credentials. For steps, seeAuthenticate and authorize as a Google Chat app.
- Choose an authorization scope based on whether you want to authenticate as a user or the Chat app.
- A Google Chat space where the authenticated user or calling Chat app is a member. To authenticate as the Chat app, add the Chat app to the space.
To get details about a membership in Google Chat, pass the following in your request:
- Withapp authentication, specify the
chat.botauthorization scope. Withuser authentication, specify thechat.memberships.readonlyorchat.membershipsauthorization scope. As a best practice, choose the most restrictive scope that still allows your app to function. - Call theGetMembership()method.
- Pass the
nameof the membership to get. Obtain the membership name from the membership resource of Google Chat.
Get a membership with user authentication
Here's how to get a membership withuser authentication:
Node.js
Python
Java
Apps Script
To run this sample, replace the following:
SPACE_NAME: the ID from the space'sname. You can obtain the ID by calling theListSpaces() method or from the space's URL.MEMBER_NAME: the ID from the member'sname. You can obtain the ID by calling theListMemberships() method.
The Chat API returns an instance ofMembershipdetailing the specified membership.
Get a membership with app authentication
Here's how to get a membership withapp authentication:
Node.js
Python
Java
Apps Script
To run this sample, replace the following:
SPACE_NAME: the ID from the space'sname. You can obtain the ID by calling theListSpaces() method or from the space's URL.MEMBER_NAME: the ID from the member'sname. You can obtain the ID by calling theListMemberships() method.
The Chat API returns an instance ofMembershipdetailing the specified membership.
Get details about memberships as a Google Workspace administrator
If you're a Google Workspace administrator, you can call theGetMembership() method to retrieve details about a membership for any user in your Google Workspace organization.
To call this method as a Google Workspace administrator, do the following:
- Call the method using user authentication, and specify anauthorization scopethat supports calling the method usingadministrator privileges.
- In your request, specify the query parameter
useAdminAccesstotrue.
For more information and examples, seeManage Google Chat spaces as a Google Workspace administrator.