列出章節

本指南說明如何使用 Google Chat API Section 資源的 list 方法,列出 Google Chat 中可供已驗證使用者存取的區段。

詳情請參閱「在 Google Chat 中建立及整理區段」。

必要條件

Python

列出章節

如要列出需要使用者驗證的章節,請在要求中傳遞下列內容:

  • 指定 chat.users.sectionschat.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 資源清單。