แสดงรายการสมาชิกในพื้นที่ทำงาน

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

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

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

Python

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

แสดงรายการสมาชิกในพื้นที่ทำงานที่มีการตรวจสอบสิทธิ์ผู้ใช้

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

ตัวอย่างต่อไปนี้แสดงรายชื่อสมาชิกใน Google Group, สมาชิกที่เป็นมนุษย์ และในแอป ผู้ใช้ที่ตรวจสอบสิทธิ์แล้ว

Python

  1. สร้างไฟล์ชื่อ chat_member_list_user.py ในไดเรกทอรีการทำงาน
  2. รวมรหัสต่อไปนี้ใน chat_member_list_user.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 lists Google Group, human, and app members in a specified space.
        '''
    
        # 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().list(
    
            # The space for which to list memberships.
            parent = 'spaces/SPACE',
    
            # Set this parameter to list Google Groups.
            showGroups = 'true'
    
        ).execute()
    
        # Prints the list of memberships.
        print(result)
    
    if __name__ == '__main__':
        main()
    
  3. ในโค้ด ให้แทนที่ SPACE ด้วยชื่อพื้นที่ทำงาน ซึ่ง ที่คุณจะได้รับจาก spaces.list วิธี ใน Chat API หรือจาก URL ของพื้นที่ทำงาน

  4. ในไดเรกทอรีการทำงาน ให้สร้างและเรียกใช้ตัวอย่างด้วยคำสั่งต่อไปนี้

    python3 chat_member_list_user.py
    

Google Chat API จะแสดงรายการสมาชิก Google Group, บุคคล และสมาชิกของแอปจาก พื้นที่ทำงานที่ระบุ

แสดงรายการสมาชิกในพื้นที่ทำงานด้วยการตรวจสอบสิทธิ์แอป

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

ตัวอย่างต่อไปนี้แสดงรายชื่อสมาชิกในพื้นที่ทำงานของผู้ใช้ (ไม่ใช่ผู้จัดการพื้นที่ทำงาน) ที่มองเห็นได้ ในแอป Chat:

Python

  1. สร้างไฟล์ชื่อ chat_member_list_app.py ในไดเรกทอรีการทำงาน
  2. รวมรหัสต่อไปนี้ใน chat_member_list_app.py:

    from google.oauth2 import service_account
    from apiclient.discovery import build
    
    # Specify required scopes.
    SCOPES = ['https://www.googleapis.com/auth/chat.bot']
    
    # Specify service account details.
    CREDENTIALS = (
        service_account.Credentials.from_service_account_file('credentials.json')
        .with_scopes(SCOPES)
    )
    
    # Build the URI and authenticate with the service account.
    chat = build('chat', 'v1', credentials=CREDENTIALS)
    
    # Use the service endpoint to call Chat API.
    result = chat.spaces().members().list(
    
            # The space for which to list memberships.
            parent = 'spaces/SPACE',
    
            # An optional filter that returns only human space members.
            filter = 'member.type = "HUMAN" AND role = "ROLE_MEMBER"'
    
        ).execute()
    
    print(result)
    
  3. ในโค้ด ให้แทนที่ SPACE ด้วยชื่อพื้นที่ทำงาน ซึ่ง ที่คุณจะได้รับจาก spaces.list วิธี ใน Chat API หรือจาก URL ของพื้นที่ทำงาน

  4. ในไดเรกทอรีการทำงาน ให้สร้างและเรียกใช้ตัวอย่างด้วยคำสั่งต่อไปนี้

    python3 chat_member_list_app.py
    

Google Chat API จะแสดงรายชื่อสมาชิกในพื้นที่ทำงาน (ไม่รวมพื้นที่ทำงาน) ผู้จัดการ) จากพื้นที่ทำงานที่ระบุ

ปรับแต่งการใส่เลขหน้าหรือกรองรายการ

หากต้องการส่งการเป็นสมาชิก ให้ส่งพารามิเตอร์การค้นหาต่อไปนี้ไปยัง ปรับแต่งการใส่เลขหน้าหรือตัวกรองการเป็นสมาชิกที่แสดง

  • pageSize: จำนวนการเป็นสมาชิกสูงสุดที่จะแสดง บริการอาจ จะแสดงผลน้อยกว่าค่านี้ หากไม่ได้ระบุ สามารถเว้นวรรคได้สูงสุด 100 ช่อง ส่งคืนแล้ว ค่าสูงสุดคือ 1,000 ค่าที่สูงกว่า 1,000 ก็เปลี่ยนเป็น 1,000
  • pageToken: โทเค็นของหน้าเว็บที่ได้รับจากการเรียกใช้รายการพื้นที่ทำงานก่อนหน้า ระบุโทเค็นนี้เพื่อเรียกข้อมูลหน้าถัดไป เมื่อใส่เลขหน้า พารามิเตอร์ ค่าตัวกรองควรตรงกับการเรียกใช้ที่ระบุโทเค็นหน้าเว็บ ส่งผ่าน ค่าที่แตกต่างกันอาจนำไปสู่ผลลัพธ์ที่ไม่คาดคิด
  • filter: ตัวกรองการค้นหา ต้องมี การตรวจสอบสิทธิ์ผู้ใช้ โปรดดูรายละเอียดการค้นหาที่รองรับที่หัวข้อ spaces.members.list วิธี