스페이스 삭제하기

이 가이드에서는 다음의 Space 리소스에서 delete 메서드를 사용하는 방법을 설명합니다. Google Chat API를 사용하여 더 이상 필요하지 않은 이름이 지정된 스페이스를 삭제합니다. 삭제 중 스페이스는 메시지 및 메시지, 음성메시지를 비롯해 첨부파일을 들을 수 있습니다.

Space 리소스 는 사람과 채팅 앱이 메시지를 보낼 수 있는 위치를 나타냅니다. 파일 공유, 공동작업 등이 가능합니다 다음과 같은 여러 유형의 스페이스가 있습니다.

  • 채팅 메시지 (DM)는 사용자 2명 또는 상대방과 채팅 앱
  • 그룹 채팅은 세 명 이상의 사용자와 채팅 앱
  • 이름이 지정된 스페이스는 사용자가 메시지를 보내고, 파일을 공유하고, 협업할 수 있습니다

기본 요건

Python

  • Python 3.6 이상
  • pip 패키지 관리 도구
  • Python용 최신 Google 클라이언트 라이브러리입니다. 이러한 앱을 설치하거나 업데이트하려면 다음 단계를 따르세요. 명령줄 인터페이스에서 다음 명령어를 실행합니다.

    pip3 install --upgrade google-api-python-client google-auth-oauthlib
    
  • Google Chat API가 사용 설정되고 구성된 Google Cloud 프로젝트 단계는 다음을 참조하세요. Google Chat 앱을 빌드합니다.
  • 채팅 앱에 승인이 구성되어 있습니다. 삭제 중 필요한 만큼 사용자 인증 권한이 있는 사용자의 chat.delete 승인 범위 지정된 스페이스를 삭제합니다.

Node.js

  • Node.js 및 npm
  • Node.js용 최신 Google 클라이언트 라이브러리입니다. 설치하려면 다음을 실행합니다. 명령줄 인터페이스에서 다음 명령어를 실행합니다.

    npm install @google-cloud/local-auth @googleapis/chat
    
  • Google Chat API가 사용 설정되고 구성된 Google Cloud 프로젝트 단계는 다음을 참조하세요. Google Chat 앱을 빌드합니다.
  • 채팅 앱에 승인이 구성되어 있습니다. 삭제 중 필요한 만큼 사용자 인증 권한이 있는 사용자의 chat.delete 승인 범위 지정된 스페이스를 삭제합니다.

이름이 지정된 스페이스 삭제하기

Google Chat에서 기존 스페이스를 삭제하려면 다음을 전달합니다. 다음과 같습니다.

스페이스를 삭제하는 방법은 다음과 같습니다.

Python

  1. 작업 디렉터리에 chat_space_delete.py라는 파일을 만듭니다.
  2. chat_space_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.delete"]
    
    def main():
        '''
        Authenticates with Chat API via user credentials,
        then deletes the 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().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.py
    

Node.js

  1. 작업 디렉터리에 delete-space.js라는 파일을 만듭니다.
  2. delete-space.js에 다음 코드를 포함합니다.

    const chat = require('@googleapis/chat');
    const {authenticate} = require('@google-cloud/local-auth');
    
    /**
    * Deletes a Chat space.
    * @return {!Promise<!Object>}
    */
    async function deleteSpace() {
      const scopes = [
        'https://www.googleapis.com/auth/chat.delete',
      ];
    
      const authClient =
          await authenticate({scopes, keyfilePath: 'client_secrets.json'});
    
      const chatClient = await chat.chat({version: 'v1', auth: authClient});
    
      return await chatClient.spaces.delete({name: 'spaces/SPACE'});
    }
    
    deleteSpace().then(console.log);
    
  3. 코드에서 SPACE을 공백 이름으로 바꿉니다. GCP 콘솔에서 spaces.list 메서드 Chat API 또는 스페이스의 URL에서 가져올 수 있습니다.

  4. 작업 디렉터리에서 샘플을 실행합니다.

    node delete-space.js
    

    성공한 경우 응답 본문이 비어 있으며, 이는 공백이 있음을 나타냅니다. 이(가) 삭제되었습니다.