Google Chat
How to list Google Chat spaces
Call spaces.list for a page of spaces the caller belongs to. Use Google's Python client to iterate the same results in an application.
Documentation reviewed · 2 methods with sources
Ways to do it
API
GET /v1/spaces
List spaces the authenticated caller belongs to. Use filter to request named spaces and nextPageToken to retrieve more results.
Read source: Google Chat spaces.list REST reference- Requirements
- The Google Chat API enabled and a user OAuth token with https://www.googleapis.com/auth/chat.spaces.readonly for this read-only example.
- Limitations
- Pages default to at most 100 spaces and cap at 1,000. Keep the filter the same when using a page token.
Example shell
curl --fail --get -H "Authorization: Bearer $GOOGLE_CHAT_TOKEN" \
--data-urlencode 'filter=spaceType = "SPACE"' --data-urlencode 'pageSize=100' \
https://chat.googleapis.com/v1/spacesSDK
Python ChatServiceClient.list_spaces
Send a ListSpacesRequest and iterate the returned pager to read matching spaces from successive pages.
Read source: Google Chat list spaces guide and Python samples- Requirements
- The google-apps-chat package, the Google Chat API enabled, and authorized user credentials with https://www.googleapis.com/auth/chat.spaces.readonly.
- Limitations
- The pager only lists spaces visible to the authenticated user. Iterating across results can make multiple requests.
Example text
from google.apps import chat_v1
# credentials is an authorized user OAuth credential.
client = chat_v1.ChatServiceClient(credentials=credentials)
request = chat_v1.ListSpacesRequest(filter='space_type = "SPACE"', page_size=100)
for space in client.list_spaces(request=request):
print(space.name)