แสดงรายการความรู้สึกสำหรับข้อความ

คำแนะนำนี้จะอธิบายวิธีใช้เมธอด list ในแหล่งข้อมูล Reaction ของ Google Chat API เพื่อแสดงรีแอ็กชันสำหรับข้อความ เช่น 👍, 🚲 และ 🌞

แหล่งข้อมูล Reaction รายการ แสดงอีโมจิที่ผู้คนใช้แสดงความรู้สึกต่อข้อความได้ เช่น 👍, 🚲, และ 🌞

ข้อกำหนดเบื้องต้น

Python

  • ธุรกิจหรือองค์กร บัญชี Google Workspace ที่มีสิทธิ์เข้าถึง Google Chat
  • 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 จะแสดงผลอาร์เรย์ของความรู้สึกที่มีการแบ่งหน้า