ลบพื้นที่ทำงาน

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

หากคุณเป็นผู้ดูแลระบบ Google Workspace คุณสามารถเรียกใช้เมธอด delete() เพื่อลบพื้นที่ทำงานที่มีชื่อในองค์กร Google Workspace ได้

Spaceทรัพยากร แสดงถึงสถานที่ที่ผู้ใช้และแอป Chat สามารถส่งข้อความ แชร์ไฟล์ และทำงานร่วมกันได้ พื้นที่ทำงานมีหลายประเภท ดังนี้

  • ข้อความส่วนตัว (DM) คือการสนทนาระหว่างผู้ใช้ 2 คนหรือผู้ใช้กับแอป Chat
  • แชทกลุ่มคือการสนทนาระหว่างผู้ใช้ตั้งแต่ 3 คนขึ้นไปและแอป Chat
  • พื้นที่ทำงานที่มีชื่อคือพื้นที่ถาวรที่ผู้คนใช้ส่งข้อความ แชร์ไฟล์ และทำงานร่วมกัน

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

Node.js

  • บัญชี Google Workspace สำหรับธุรกิจหรือองค์กร ที่มีสิทธิ์เข้าถึง Google Chat

ลบพื้นที่ทำงานที่มีชื่อในฐานะผู้ใช้

หากต้องการลบพื้นที่ทำงานที่มีอยู่ใน Google Chat ที่มีการตรวจสอบสิทธิ์ผู้ใช้ ให้ส่งข้อมูลต่อไปนี้ในคำขอ

  • ระบุchat.deleteขอบเขตการให้สิทธิ์
  • เรียกใช้เมธอด DeleteSpace()
  • ส่ง name ของพื้นที่ทำงานที่จะลบ

วิธีลบพื้นที่ทำงานมีดังนี้

Node.js

chat/client-libraries/cloud/delete-space-user-cred.js
import {createClientWithUserCredentials} from './authentication-utils.js';  const USER_AUTH_OAUTH_SCOPES = ['https://www.googleapis.com/auth/chat.delete'];  // This sample shows how to delete a space with user credential async function main() {   // Create a client   const chatClient = await createClientWithUserCredentials(USER_AUTH_OAUTH_SCOPES);    // Initialize request argument(s)   const request = {     // Replace SPACE_NAME here     name: 'spaces/SPACE_NAME'   };    // Make the request   const response = await chatClient.deleteSpace(request);    // Handle the response   console.log(response); }  main().catch(console.error);

หากต้องการเรียกใช้ตัวอย่างนี้ ให้แทนที่ SPACE_NAME ด้วยรหัสจาก ฟิลด์ name ของพื้นที่ทำงาน คุณรับรหัสได้โดยการเรียกใช้เมธอด ListSpaces() หรือจาก URL ของพื้นที่ทำงาน

ลบพื้นที่ทำงานที่มีชื่อในฐานะแอป Chat

การตรวจสอบสิทธิ์แอปต้องมีการอนุมัติจากผู้ดูแลระบบแบบครั้งเดียว

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

หากต้องการลบพื้นที่ที่มีอยู่ใน Google Chat ด้วยการตรวจสอบสิทธิ์แอป ให้ส่งข้อมูลต่อไปนี้ในคำขอ

  • ระบุchat.app.deleteขอบเขตการให้สิทธิ์
  • เรียกใช้เมธอด delete ในSpaceทรัพยากร
  • ส่ง name ของพื้นที่ทำงานที่จะลบ

เขียนสคริปต์ที่เรียกใช้ Chat API

วิธีลบพื้นที่ทำงานมีดังนี้

Python

  1. สร้างไฟล์ชื่อ chat_space_delete_app.py ในไดเรกทอรีการทำงาน
  2. ใส่โค้ดต่อไปนี้ใน chat_space_delete_app.py

    from google.oauth2 import service_account from apiclient.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.app.delete"]  def main():     '''     Authenticates with Chat API using app authentication,     then deletes the specified space.     '''      # Specify service account details.     creds = (         service_account.Credentials.from_service_account_file('credentials.json')         .with_scopes(SCOPES)     )      # Build a service endpoint for Chat API.     chat = build('chat', 'v1', credentials=creds)      # Use the service endpoint to call Chat API.     result = chat.spaces().delete(            # The space 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.           name='spaces/SPACE'        ).execute()      # Print Chat API's response in your command line interface.     # When deleting a space, the response body is empty.     print(result)  if __name__ == '__main__':     main() 
  3. ในโค้ด ให้แทนที่ค่าต่อไปนี้

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

    python3 chat_space_delete_app.py

หากทำสำเร็จ เนื้อหาการตอบกลับจะว่างเปล่า ซึ่งแสดงว่าระบบได้ลบพื้นที่แล้ว

ลบพื้นที่ทำงานที่มีชื่อในฐานะผู้ดูแลระบบ Google Workspace

หากคุณเป็นผู้ดูแลระบบ Google Workspace คุณสามารถเรียกใช้เมธอด DeleteSpace() เพื่อลบพื้นที่ทำงานที่มีชื่อในองค์กร Google Workspace ของคุณได้

หากต้องการเรียกใช้เมธอดนี้ในฐานะผู้ดูแลระบบ Google Workspace ให้ทำดังนี้

ดูข้อมูลเพิ่มเติมและตัวอย่างได้ที่หัวข้อจัดการพื้นที่ใน Google Chat ในฐานะผู้ดูแลระบบ Google Workspace