Google Chat 스페이스에서 사용자의 멤버십 업데이트하기

이 가이드에서는 Google Chat API의 Membership 리소스에서 update() 메서드를 사용하여 스페이스 멤버를 스페이스 관리자로 변경하거나 스페이스 관리자를 스페이스 멤버로 변경하는 등 멤버십에 관한 속성을 변경하는 방법을 설명합니다.

Google Workspace 관리자는 update() 메서드를 호출하여 Google Workspace 조직의 스페이스 멤버십을 업데이트할 수 있습니다.

Membership 리소스는 실제 사용자 또는 Google Chat 앱이 스페이스에 초대되었는지, 스페이스에 속해 있는지, 스페이스에 없는지를 나타냅니다.

기본 요건

Node.js

멤버십 업데이트

스페이스 멤버십을 업데이트하려면 요청에 다음을 전달하세요.

  • 승인 범위를 지정합니다.
    • 사용자 인증을 사용하여 chat.memberships 승인 범위를 지정합니다.
    • 앱 인증을 사용하여 chat.app.memberships 승인 범위를 지정합니다. 앱 인증으로 멤버십을 업데이트할 때는 채팅 앱으로 만든 스페이스의 멤버십만 업데이트할 수 있습니다. 앱 인증에는 일회성 관리자 승인이 필요합니다.
  • UpdateMembership() 메서드를 호출합니다.
  • 다음과 같이 membershipMembership의 인스턴스로 전달합니다.
    • 업데이트할 멤버십으로 설정된 name 필드입니다. 여기에는 스페이스 ID와 멤버 ID가 포함됩니다.
    • 새 값으로 업데이트할 멤버십 필드입니다.
  • 업데이트할 멤버십의 측면을 지정하기 위해 updateMask를 전달합니다. 여기에는 다음이 포함됩니다.
    • role: Chat 스페이스 내 사용자의 역할로, 스페이스에서 허용되는 작업을 결정합니다. 가능한 값은 다음과 같습니다.
      • ROLE_MEMBER: 스페이스의 구성원입니다. 사용자에게 스페이스에 메시지를 보내는 것과 같은 기본 권한이 있습니다. 1:1 및 이름이 지정되지 않은 그룹 대화에서는 모든 사용자에게 이 역할이 있습니다.
      • ROLE_MANAGER: 스페이스 관리자 사용자에게 모든 기본 권한과 회원을 추가하거나 삭제하는 등 스페이스를 관리할 수 있는 관리 권한이 있습니다. spaceTypeSPACE(이름이 지정된 스페이스)인 스페이스에서만 지원됩니다.

사용자로서 일반 스페이스 멤버를 스페이스 관리자로 지정하기

다음 예에서는 사용자 인증을 사용하여 Chat API를 호출하여 roleROLE_MANAGER로 지정하여 일반 스페이스 구성원을 스페이스 관리자로 만듭니다.

Node.js

chat/client-libraries/cloud/update-membership-user-cred.js
import {createClientWithUserCredentials} from './authentication-utils.js';

const USER_AUTH_OAUTH_SCOPES = ['https://www.googleapis.com/auth/chat.memberships'];

// This sample shows how to update a membership with user credential
async function main() {
  // Create a client
  const chatClient = await createClientWithUserCredentials(USER_AUTH_OAUTH_SCOPES);

  // Initialize request argument(s)
  const request = {
    membership: {
      // Replace SPACE_NAME and MEMBER_NAME here
      name: 'spaces/SPACE_NAME/members/MEMBER_NAME',
      // Replace ROLE_NAME here with ROLE_MEMBER or ROLE_MANAGER
      role: 'ROLE_NAME'
    },
    updateMask: {
      // The field paths to update.
      paths: ['role']
    }
  };

  // Make the request
  const response = await chatClient.updateMembership(request);

  // Handle the response
  console.log(response);
}

main().catch(console.error);

샘플을 실행하려면 다음을 바꿉니다.

  • SPACE_NAME: 스페이스의 name에서 가져온 ID입니다. ListSpaces() 메서드를 호출하거나 스페이스의 URL에서 ID를 가져올 수 있습니다.
  • MEMBER_NAME: 멤버십의 name에서 가져온 ID입니다. ListMemberships() 메서드를 호출하거나 Chat API를 사용하여 비동기식으로 멤버십을 만든 후 반환되는 응답 본문에서 ID를 가져올 수 있습니다.
  • ROLE_NAME: 업데이트된 역할 ROLE_MANAGER

Google Chat API는 지정된 멤버십을 스페이스 관리자로 업데이트하고 Membership 인스턴스를 반환합니다.

사용자로 스페이스 관리자를 일반 멤버로 지정하기

다음 예에서는 사용자 인증을 사용하여 Chat API를 호출하여 roleROLE_MEMBER로 지정하여 스페이스 관리자를 일반 스페이스 구성원으로 만듭니다.

Node.js

chat/client-libraries/cloud/update-membership-user-cred.js
import {createClientWithUserCredentials} from './authentication-utils.js';

const USER_AUTH_OAUTH_SCOPES = ['https://www.googleapis.com/auth/chat.memberships'];

// This sample shows how to update a membership with user credential
async function main() {
  // Create a client
  const chatClient = await createClientWithUserCredentials(USER_AUTH_OAUTH_SCOPES);

  // Initialize request argument(s)
  const request = {
    membership: {
      // Replace SPACE_NAME and MEMBER_NAME here
      name: 'spaces/SPACE_NAME/members/MEMBER_NAME',
      // Replace ROLE_NAME here with ROLE_MEMBER or ROLE_MANAGER
      role: 'ROLE_NAME'
    },
    updateMask: {
      // The field paths to update.
      paths: ['role']
    }
  };

  // Make the request
  const response = await chatClient.updateMembership(request);

  // Handle the response
  console.log(response);
}

main().catch(console.error);

샘플을 실행하려면 다음을 바꿉니다.

  • SPACE_NAME: 스페이스의 name에서 가져온 ID입니다. ListSpaces() 메서드를 호출하거나 스페이스의 URL에서 ID를 가져올 수 있습니다.
  • MEMBER_NAME: 멤버십의 name에서 가져온 ID입니다. ListMemberships() 메서드를 호출하거나 Chat API를 사용하여 비동기식으로 멤버십을 만든 후 반환되는 응답 본문에서 ID를 가져올 수 있습니다.
  • ROLE_NAME: 업데이트된 역할 ROLE_MEMBER

Google Chat API는 지정된 멤버십을 스페이스 관리자로 업데이트하고 Membership 인스턴스를 반환합니다.

Chat 앱으로 일반 스페이스 멤버를 스페이스 관리자로 지정하기

앱 인증에는 일회성 관리자 승인이 필요합니다.

Chat API를 호출하는 스크립트 작성

다음 예에서는 앱 인증을 사용하여 Chat API를 호출하여 업데이트된 멤버십 속성을 지정하는 body에서 roleROLE_MANAGER로 지정하여 일반 스페이스 구성원을 스페이스 관리자로 만듭니다.

Python

  1. 작업 디렉터리에 chat_membership_update_to_manager_app.py이라는 파일을 만듭니다.
  2. chat_membership_update_to_manager_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.memberships"]
    
    def main():
        '''
        Authenticates with Chat API using app authentication,
        then updates a specified space member to change
        it from a regular member to a space manager.
        '''
    
        # 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().members().patch(
    
            # The membership to update, and the updated role.
            #
            # Replace SPACE with a space name.
            # Obtain the space name from the spaces resource of Chat API,
            # or from a space's URL.
            #
            # Replace MEMBERSHIP with a membership name.
            # Obtain the membership name from the membership of Chat API.
            name='spaces/SPACE/members/MEMBERSHIP',
            updateMask='role',
            body={'role': 'ROLE_MANAGER'}
    
          ).execute()
    
        # Prints details about the updated membership.
        print(result)
    
    if __name__ == '__main__':
        main()
    
  3. 코드에서 다음을 바꿉니다.

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

    python3 chat_membership_update_to_manager_app.py

Chat 앱으로 스페이스 관리자를 일반 회원으로 만들기

앱 인증에는 일회성 관리자 승인이 필요합니다.

Chat API를 호출하는 스크립트 작성

다음 예에서는 앱 인증을 사용하여 Chat API를 호출하여 업데이트된 멤버십 속성을 지정하는 body에서 roleROLE_MEMBER로 지정하여 스페이스 관리자를 일반 스페이스 구성원으로 만듭니다.

Python

  1. 작업 디렉터리에 chat_membership_update_to_member_app.py이라는 파일을 만듭니다.
  2. chat_membership_update_to_member_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.memberships"]
    
    def main():
        '''
        Authenticates with Chat API via user credentials,
        then updates a specified space member to change
        it from a regular member to a space manager.
        '''
    
        # 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().members().patch(
    
            # The membership to update, and the updated role.
            #
            # Replace SPACE with a space name.
            # Obtain the space name from the spaces resource of Chat API,
            # or from a space's URL.
            #
            # Replace MEMBERSHIP with a membership name.
            # Obtain the membership name from the membership of Chat API.
            name='spaces/SPACE/members/MEMBERSHIP',
            updateMask='role',
            body={'role': 'ROLE_MEMBER'}
    
          ).execute()
    
        # Prints details about the updated membership.
        print(result)
    
    if __name__ == '__main__':
        main()
    
  3. 코드에서 다음을 바꿉니다.

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

    python3 chat_membership_update_to_member_app.py

Google Workspace 관리자로 구성원십 업데이트하기

Google Workspace 관리자는 update() 메서드를 호출하여 Google Workspace 조직의 모든 스페이스의 멤버십을 업데이트할 수 있습니다.

Google Workspace 관리자로 이 메서드를 호출하려면 다음 단계를 따르세요.

  • 사용자 인증을 사용하여 메서드를 호출하고 관리자 권한을 사용하여 메서드 호출을 지원하는 승인 범위를 지정합니다.
  • 요청에서 useAdminAccess 쿼리 매개변수를 true로 지정합니다.

자세한 내용과 예시는 Google Workspace 관리자로 Google Chat 스페이스 관리하기를 참고하세요.