メッセージのリアクションを一覧表示する

このガイドでは、Reaction リソースで list メソッドを使用する方法について説明します の Google Chat API を使って、fitbit、🚲?、🔥? などのメッセージに対するリアクションを一覧表示できます。

Reaction リソース はメッセージにリアクションするために使用できる絵文字を表します(例: 直、🚲?、 そして ☀。

前提条件

Python

  • Python 3.6 以降
  • pip パッケージ管理ツール
  • 最新の Google クライアント ライブラリ。インストールまたは更新する手順は次のとおりです。 コマンドライン インターフェースで次のコマンドを実行します。
    pip3 install --upgrade google-api-python-client google-auth-oauthlib
    

リアクションを一覧表示する

メッセージのリアクションを一覧表示するには、リクエストに次のものを渡します。

  • chat.messages.reactions.readonlychat.messages.reactions、 承認スコープは chat.messages.readonly または chat.messages です。
  • 呼び出し [list メソッド]/workspace(/chat/api/reference/rest/v1/spaces.messages.reactions/list) 日付 Reaction リソース

次の例では、指定したメッセージのリアクションを一覧表示します。

Python

  1. 作業ディレクトリに、chat_reactions_list.py という名前のファイルを作成します。
  2. chat_reactions_list.py に次のコードを含めます。

    from google_auth_oauthlib.flow import InstalledAppFlow
    from googleapiclient.discovery import build
    
    # Define your app's authorization scopes.
    # When modifying these scopes, delete the file token.json, if it exists.
    SCOPES = ["https://www.googleapis.com/auth/chat.messages.reactions.readonly"]
    
    def main():
        '''
        Authenticates with Chat API via user credentials,
        then lists reactions to a message.
        '''
    
        # Authenticate with Google Workspace
        # and get user authorization.
        flow = InstalledAppFlow.from_client_secrets_file(
                          'client_secrets.json', SCOPES)
        creds = flow.run_local_server()
    
        # Build a service endpoint for Chat API.
        chat = build('chat', 'v1', credentials=creds)
    
        # Use the service endpoint to call Chat API.
        result = chat.spaces().messages().reactions().list(
    
            # The message to list reactions to.
            #
            # Replace SPACE with a space name.
            # Obtain the space name from the spaces resource of Chat API,
            # or from a space's URL.
            #
            # Replace MESSAGE with a message name.
            # Obtain the message name from the response body returned
            # after creating a message asynchronously with Chat REST API.
            parent = 'spaces/SPACE/messages/MESSAGE'
    
        ).execute()
    
        # Prints details about the created reactions.
        print(result)
    
    if __name__ == '__main__':
        main()
    
  3. コードの次のように置き換えます。

    • SPACE: スペース名。 spaces.list メソッド スペースの URL から取得できます。
    • MESSAGE: メッセージ名。取得して取得できます。 非同期でメッセージを作成した後に返されるレスポンス本文から Chat API、または カスタム名 自動的に割り当てられます。
  4. 作業ディレクトリでサンプルをビルドして実行します。

    python3 chat_reactions_list.py
    

Chat API は、リアクションのページ分けされた配列を返します。