메시지에 대한 반응 나열

이 가이드에서는 Reaction 리소스에서 list 메서드를 사용하는 방법을 설명합니다. Google Chat API를 사용하여 메시지에 대한 반응을 나열합니다. 예: 👍, ↘, 재정의합니다.

Reaction 리소스 사람들이 메시지에 반응할 때 사용할 수 있는 이모티콘을 나타냅니다(예: 👍, ↩, 그리고 🏠

기본 요건

Python

  • Python 3.6 이상
  • pip 패키지 관리 도구
  • 최신 Google 클라이언트 라이브러리 이러한 앱을 설치하거나 업데이트하려면 다음 단계를 따르세요. 명령줄 인터페이스에서 다음 명령어를 실행합니다.
    pip3 install --upgrade google-api-python-client google-auth-oauthlib
    

반응 나열

메시지에 대한 반응을 나열하려면 요청에 다음을 전달합니다.

  • chat.messages.reactions.readonly, chat.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 메서드 Chat API 또는 스페이스의 URL에서 가져올 수 있습니다.
    • MESSAGE: 가져올 수 있는 메시지 이름입니다. 비동기식으로 메시지를 만든 후 반환된 응답 본문에서 삭제 Chat API 또는 맞춤 이름 메시지를 만들 때 할당됩니다.
  4. 작업 디렉터리에서 샘플을 빌드하고 실행합니다.

    python3 chat_reactions_list.py
    

Chat API는 페이지로 나눈 반응 배열을 반환합니다.