This guide explains how to use the
list
method on the Section resource of the Google Chat API to list sections available to the authenticated user in Google Chat.
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 sections
To list sections with user authentication, pass the following in your request:
- Specify the
chat.users.sectionsorchat.users.sections.readonlyauthorization scope. - Call the
ListSectionsmethod. - Set
parenttousers/me.
The following example lists sections:
Python
from google.cloud import chat_v1
def list_sections():
# Create a client
client = chat_v1.ChatServiceClient()
# Initialize request
request = chat_v1.ListSectionsRequest(
parent="users/me"
)
# Make the request
page_result = client.list_sections(request=request)
# Handle the response
for section in page_result:
print(section)
The Chat API returns a list of
Section resources.
Related topics
- Create a section
- Update a section
- Delete a section
- Change the position of a section
- List spaces in a section
- Move a space to a different section