本指南介绍了如何对 Google Chat API 的 Section 资源使用
list
方法,以列出 Google Chat 中经过身份验证的用户可用的部分。
如需了解详情,请参阅 在 Google Chat 中创建和整理部分。
前提条件
Python
- 拥有 Google Workspace访问权限的 Business 或 Enterprise 账号,可访问 Google Chat。
- 设置环境:
- 创建 Google Cloud 项目。
- 配置 OAuth 权限请求页面。
- 启用并配置 Google Chat API,为您的 Chat 应用设置名称、 图标和说明。
- 安装 Python Cloud 客户端库。
-
为桌面应用创建 OAuth 客户端 ID 凭据。如需运行本
指南中的示例,请将凭据另存为名为
credentials.json的 JSON 文件,并保存到本地 目录中。
- 选择支持用户身份验证的授权范围。
列出部分
如需列出具有 用户身份验证的部分,请在请求中传递以下内容:
- 指定
chat.users.sections或chat.users.sections.readonly授权范围。 - 调用
ListSections方法。 - 将
parent设置为users/me。
以下示例列出了部分:
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)
Chat API 会返回
Section资源的列表。