스페이스에서 멤버 삭제하기

이 가이드에서는 membership 리소스에서 delete 메서드를 사용하는 방법을 설명합니다. 를 사용하여 스페이스에서 참여자를 삭제할 수 있습니다. 멤버십입니다. 유일한 스페이스 관리자인 경우 스페이스 관리자를 삭제할 수 없습니다. 표시됩니다. 이 사용자를 삭제하기 전에 다른 사용자를 스페이스 관리자로 지정하세요. 멤버십입니다.

Membership 리소스 사람 또는 Google Chat 앱이 초대되었는지 여부를 나타냅니다. 빈 공간을 사용할 수 있습니다.

기본 요건

Python

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

스페이스에서 멤버 삭제하기

앱에서 사용자, Google 그룹 또는 채팅 앱을 삭제하려면 다음 단계를 따르세요. 스페이스:

  • 사용자 또는 Google 그룹을 삭제하려면 chat.memberships 승인을 지정합니다. 범위를 제공합니다 채팅 앱을 삭제하려면 다음을 지정합니다. 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 메서드에서 호출 채팅 API에서 지원됩니다. 앱의 멤버십을 삭제하려면 app에서 MEMBER

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

    python3 chat_membership_delete.py
    

성공하면 응답 본문이 'state': 'NOT_A_MEMBER': 멤버가 더 이상 스페이스에 없음을 나타냅니다.

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