This guide explains how to use the
list
method on the SectionItem resource of the Google Chat API to list items (such as spaces) in a section.
Only spaces can be section items. For more information, see Create and organize sections in Google Chat.
Prerequisites
Python
- A Business or Enterprise Google Workspace account with access to Google 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 OAuth client ID credentials for a desktop application. To run the sample in this
guide, save the credentials as a JSON file named
credentials.jsonto your local directory.
- Choose an authorization scope that supports user authentication.
List spaces in a section
To list spaces in a section with user authentication, pass the following in your request:
- Specify the
chat.users.sectionsorchat.users.sections.readonlyauthorization scope. - Call the
ListSectionItemsmethod. - Set
parentto the resource name of the section.
The following example lists spaces in a section:
Python
from google.cloud import chat_v1
def list_section_items():
# Create a client
client = chat_v1.ChatServiceClient()
# Initialize request
request = chat_v1.ListSectionItemsRequest(
parent="SECTION_NAME"
)
# Make the request
page_result = client.list_section_items(request=request)
# Handle the response
for item in page_result:
print(item)
To run this sample, replace the following:
SECTION_NAME: The resource name of the section. You can obtain the resource name by calling theListSectionsmethod.
The Chat API returns a list of
SectionItem resources.
Related topics
- Create a section
- Update a section
- Delete a section
- Change the position of a section
- List sections
- Move a space to a different section