นำสมาชิกออกจากพื้นที่ทำงาน

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

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

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

Python

  • Python 3.6 ขึ้นไป
  • PIP เครื่องมือจัดการแพ็กเกจ
  • ไลบรารีของไคลเอ็นต์ Google ล่าสุดสำหรับ Python หากต้องการติดตั้งหรืออัปเดตส่วนขยาย เรียกใช้คำสั่งต่อไปนี้ในอินเทอร์เฟซบรรทัดคำสั่ง

    pip3 install --upgrade google-api-python-client google-auth-oauthlib
    
  • โปรเจ็กต์ Google Cloud ที่เปิดใช้และกำหนดค่า Google Chat API โปรดดูขั้นตอนในหัวข้อ สร้างแอป Google Chat
  • กำหนดค่าการให้สิทธิ์สำหรับแอป Chat แล้ว กำลังลบ ข้อกำหนดการเป็นสมาชิก การตรวจสอบสิทธิ์ผู้ใช้ พร้อมด้วย ขอบเขตการให้สิทธิ์ chat.memberships หรือ chat.memberships.app จากผู้ใช้ ที่มีสิทธิ์ลบการเป็นสมาชิกที่ระบุ

นำสมาชิกออกจากพื้นที่ทำงาน

วิธีนําผู้ใช้, แอป Google Group หรือ Chat ออกจาก พื้นที่ทำงาน:

  • หากต้องการนำผู้ใช้หรือ Google Group ออก ให้ระบุการให้สิทธิ์ chat.memberships หากต้องการนำแอปใน Chat ออก ให้ระบุ chat.memberships.app ขอบเขตการให้สิทธิ์ (แอปลบได้เฉพาะขอบเขตของตนเองเท่านั้น การเป็นสมาชิก ไม่ใช่ของแอปอื่น) ตามแนวทางปฏิบัติแนะนำ ให้เลือก ขอบเขตที่จำกัดซึ่งยังคงอนุญาตให้แอปทำงานได้
  • เรียกใช้เมธอด delete ใน แหล่งข้อมูล membership
  • ส่งการเป็นสมาชิก name เพื่อลบ หากการเป็นสมาชิกเป็นของ เฉพาะผู้จัดการพื้นที่ทำงานในพื้นที่ทำงาน โปรดกำหนดให้ผู้ใช้รายอื่นเป็นผู้จัดการพื้นที่ทำงานก่อน กำลังลบการเป็นสมาชิกนี้

วิธีลบการเป็นสมาชิก

Python

  1. สร้างไฟล์ชื่อ chat_membership_delete.py ในไดเรกทอรีการทำงาน
  2. รวมรหัสต่อไปนี้ใน chat_membership_delete.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.app"]
    
    def main():
        '''
        Authenticates with Chat API via user credentials,
        then deletes the 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().delete(
    
            # The membership to delete.
            #
            # 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. To delete a Chat app's membership, replace MEMBER
            # with app; an alias for the app calling the API.
            name='spaces/SPACE/members/MEMBER'
    
        ).execute()
    
        # Print Chat API's response in your command line interface.
        # When deleting a membership, the response body is empty.
        print(result)
    
    if __name__ == '__main__':
        main()
    
  3. ในโค้ด ให้แทนที่

    • SPACE: ชื่อพื้นที่ทำงานซึ่งดูได้จาก เมธอด spaces.list ใน Chat API หรือจาก URL ของพื้นที่ทำงาน

    • MEMBER: ชื่อการเป็นสมาชิกที่คุณขอรับได้ จาก spaces.members.list Method ใน Chat API หากต้องการลบการเป็นสมาชิกของแอป ให้แทนที่ MEMBER ด้วย app

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

    python3 chat_membership_delete.py
    

หากสำเร็จ เนื้อหาการตอบกลับจะแสดงการเป็นสมาชิกที่มี 'state': 'NOT_A_MEMBER' ซึ่งแสดงว่าสมาชิกไม่ได้อยู่ในพื้นที่ทำงานแล้ว

{
    "name": "spaces/SPACE/members/MEMBER",
    "state": "NOT_A_MEMBER"
}