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

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

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

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

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

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

Node.js

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

หากต้องการลบพื้นที่ทำงานที่มีอยู่ใน 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);
}

await main();

หากต้องการเรียกใช้ตัวอย่างนี้ ให้แทนที่ 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