Get details about a space (original) (raw)
This guide explains how to use theget()method on a Space resource of the Google Chat API to see details about a space, like its display name, description, and guidelines.
If you're a Google Workspace administrator, you can call the get() method to retrieve details about any space in your Google Workspace organization.
TheSpace resourcerepresents a place where people and Chat apps can send messages, share files, and collaborate. There are several types of spaces:
- Direct messages (DMs) are conversations between two users or a user and a Chat app.
- Group chats are conversations between three or more users and Chat apps.
- Named spaces are persistent places where people send messages, share files, and collaborate.
Authenticating withapp authenticationlets a Chat app get details about a space where the Chat app is a member. Authenticating withuser authenticationlets you get spaces that the authenticated user has access to, either as a space member or aGoogle Workspace administrator.
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 a space in Google Chat, pass the following in your request:
- An authorization scope:
- Withuser authentication, specify the
chat.spaces.readonlyorchat.spacesauthorization scope. - With app authentication, specify the
chat.botauthorization scope or thechat.app.spacesscope. Thechat.app.spacesscope is available inDeveloper Preview and requires one-timeadministrator approval.
- Withuser authentication, specify the
- Call theGetSpace()method, passing the
nameof the space to get. Obtain the space name from theSpaceresource of Google Chat, or from a space's URL.
Get space details as a user
Here's how to get space details withuser authentication:
Node.js
Python
Java
Apps Script
To run this sample, replace SPACE_NAME with the ID from the space'snamefield. You can obtain the ID by calling theListSpaces()method or from the space's URL.
The Chat API returns an instance ofSpacethat details the specified space.
Get space details as a Google Workspace administrator
If you're a Google Workspace administrator, you can call the GetSpacemethod to retrieve details about any space 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.
Get space details as a Chat app
Here's how to get space details withapp authentication:
Node.js
Python
Java
Apps Script
To run this sample, replace SPACE_NAME with the ID from the space'snamefield. You can obtain the ID by calling theListSpaces()method or from the space's URL.
The Chat API returns an instance ofSpacethat details the specified space.
Limitations and considerations
- TheaccessSettings,predefinedPermissionSettings, andpermissionSettingsfields only populate when you authenticate with the
chat.app.spacesscope, and permission settings are limited to spaces the Chat app created. - Create a space.
- Set up a space.
- List spaces.
- Update a space.
- Delete a space.
- Find a direct message space.