ดูรายละเอียดเกี่ยวกับการเป็นสมาชิก

คำแนะนำนี้จะอธิบายวิธีใช้เมธอด get ในแหล่งข้อมูล membership ของ Google Chat API เพื่อดูรายละเอียดเกี่ยวกับการเป็นสมาชิกในพื้นที่ทำงาน

แหล่งข้อมูล Membership รายการ จะแสดงว่ามีการเชิญผู้ใช้ที่เป็นมนุษย์หรือแอป Google Chat หรือไม่ เพียงบางส่วน หรือไม่ปรากฏในพื้นที่ทำงาน

กำลังตรวจสอบสิทธิ์กับ การตรวจสอบสิทธิ์แอป ช่วยให้แอปใน Chat รับการเป็นสมาชิกจากพื้นที่ทำงานที่มี สิทธิ์เข้าถึงใน Google Chat (เช่น พื้นที่ทำงานที่สมาชิกเป็นสมาชิกอยู่) แต่ไม่รวม การเป็นสมาชิกของแอป Chat ซึ่งรวมถึงของตนเองด้วย กำลังตรวจสอบสิทธิ์ กับ การตรวจสอบสิทธิ์ผู้ใช้ จะแสดงการเป็นสมาชิกจากพื้นที่ทำงานที่ผู้ใช้ที่ได้รับการตรวจสอบสิทธิ์มีสิทธิ์เข้าถึง

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

Python

  • ธุรกิจหรือองค์กร บัญชี Google Workspace ที่มีสิทธิ์เข้าถึง Google Chat
  • Python 3.6 ขึ้นไป
  • เครื่องมือจัดการแพ็กเกจ pip
  • ไลบรารีของไคลเอ็นต์ Google ล่าสุด หากต้องการติดตั้งหรืออัปเดตส่วนขยาย เรียกใช้คำสั่งต่อไปนี้ในอินเทอร์เฟซบรรทัดคำสั่ง
    pip3 install --upgrade google-api-python-client google-auth-oauthlib
    

ดูรายละเอียดเกี่ยวกับการเป็นสมาชิก

หากต้องการดูรายละเอียดเกี่ยวกับการเป็นสมาชิกใน Google Chat โปรดส่งข้อมูลต่อไปนี้ใน คำขอ:

วิธีสมัครสมาชิกกับ การตรวจสอบสิทธิ์ผู้ใช้:

Python

  1. สร้างไฟล์ชื่อ chat_membership_get.py ในไดเรกทอรีการทำงาน
  2. รวมรหัสต่อไปนี้ใน chat_membership_get.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.memberships.readonly"]
    
    def main():
        '''
        Authenticates with Chat API via user credentials,
        then gets details about a specified membership.
        '''
    
        # 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().members().get(
    
            # The membership to get.
            #
            # Replace SPACE with a space name.
            # Obtain the space name from the spaces resource of Chat API,
            # or from a space's URL.
            #
            # Replace MEMBER with a membership name.
            # Obtain the membership name from the memberships resource of
            # Chat API.
            name='spaces/SPACE/members/MEMBER'
    
        ).execute()
    
        # Prints details about the membership.
        print(result)
    
    if __name__ == '__main__':
        main()
    
  3. ในโค้ด ให้แทนที่

    • SPACE: ชื่อพื้นที่ทำงานซึ่งดูได้จาก เมธอด spaces.list ใน Chat API หรือจาก URL ของพื้นที่ทำงาน
    • MEMBER: ชื่อการเป็นสมาชิกที่คุณขอรับได้ จาก spaces.members.list วิธี ใน Chat API
  4. ในไดเรกทอรีการทำงาน ให้สร้างและเรียกใช้ตัวอย่างด้วยคำสั่งต่อไปนี้

    python3 chat_membership_get.py
    

Chat API จะแสดงผลอินสแตนซ์ membership ระบุรายละเอียดการเป็นสมาชิกที่ระบุไว้