คำแนะนำนี้จะอธิบายวิธีใช้เมธอด 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
- สร้างไฟล์ชื่อ
chat_membership_delete.py
ในไดเรกทอรีการทำงาน รวมรหัสต่อไปนี้ใน
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()
ในโค้ด ให้แทนที่
SPACE
: ชื่อพื้นที่ทำงานซึ่งดูได้จาก เมธอดspaces.list
ใน Chat API หรือจาก URL ของพื้นที่ทำงานMEMBER
: ชื่อการเป็นสมาชิกที่คุณขอรับได้ จากspaces.members.list
Method ใน Chat API หากต้องการลบการเป็นสมาชิกของแอป ให้แทนที่MEMBER
ด้วยapp
ในไดเรกทอรีการทำงาน ให้สร้างและเรียกใช้ตัวอย่างด้วยคำสั่งต่อไปนี้
python3 chat_membership_delete.py
หากสำเร็จ เนื้อหาการตอบกลับจะแสดงการเป็นสมาชิกที่มี
'state': 'NOT_A_MEMBER'
ซึ่งแสดงว่าสมาชิกไม่ได้อยู่ในพื้นที่ทำงานแล้ว
{ "name": "spaces/SPACE/members/MEMBER", "state": "NOT_A_MEMBER" }
หัวข้อที่เกี่ยวข้อง
- ดูรายละเอียดเกี่ยวกับการเป็นสมาชิกของผู้ใช้หรือแอป Chat
- แสดงสมาชิกในพื้นที่ทำงาน
- อัปเดตการเป็นสมาชิกของผู้ใช้ในพื้นที่ของ Google Chat
- เชิญหรือเพิ่มผู้ใช้หรือแอป Chat ไปยังพื้นที่ทำงาน