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

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

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

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

기본 요건

Node.js

멤버십 업데이트

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

  • 승인 범위를 지정합니다.
    • 사용자 인증으로 chat.memberships 승인 범위를 지정합니다.
    • 다음으로 바꿉니다. 앱 인증 (개발자 프리뷰에서 제공) chat.app.memberships 승인 범위를 지정합니다. 배포를 업데이트할 때 멤버십을 사용하려면 다음 버전에서만 멤버십을 업데이트할 수 있습니다. Chat 앱에서 만든 스페이스 앱 인증에는 일회성 관리자 승인이 필요합니다.
  • UpdateMembership() 메서드를 호출합니다.
  • 다음과 같이 membershipMembership의 인스턴스로 전달합니다.
    • 업데이트할 멤버십으로 설정된 name 필드(스페이스 ID 포함) 회원 ID를 설정할 수 있습니다
    • 업데이트할 멤버십 필드가 새 값으로 설정됩니다.
  • updateMask를 전달하여 업데이트할 멤버십의 측면을 지정합니다. 다음이 포함됩니다. <ph type="x-smartling-placeholder">
      </ph>
    • role: Chat 스페이스 내에서의 사용자 역할로, 허용 여부를 결정합니다. 할 수 있습니다. 가능한 값은 다음과 같습니다.
      • ROLE_MEMBER: 스페이스의 구성원입니다. 사용자에게 기본 권한이 있습니다. 스페이스에 메시지를 보내는 것과 같은 기능을 예로 들 수 있습니다 1:1 및 이름이 지정되지 않은 그룹 대화에서는 모든 사용자가 이 역할을 갖습니다.
      • ROLE_MANAGER: 스페이스 관리자입니다. 사용자에게 모든 기본 권한과 회원 추가 또는 삭제와 같이 스페이스를 관리할 수 있는 관리 권한이 있습니다. spaceType 필드가 SPACE인 스페이스에서만 지원됩니다. (이름이 지정된 스페이스)

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

다음 예에서는 사용자 인증을 사용하여 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입니다. ID는 ListSpaces() 메서드를 사용하거나 스페이스의 URL에서 가져올 수 있습니다.
  • 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입니다. ID는 ListMemberships() 메서드를 호출하거나 멤버십을 만든 후 반환된 응답 본문에서 가져올 수 있습니다. Chat API와 비동기식으로 실행할 수 있습니다
  • ROLE_NAME: 업데이트된 역할(ROLE_MEMBER)입니다.

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

Chat 앱으로 일반 스페이스 회원을 스페이스 관리자로 지정하기

앱 인증에 일회성 필요 관리자 승인이 있을 수 있습니다.

API 키 만들기

개발자 프리뷰 API 메서드를 호출하려면 API 검색 문서의 비공개 개발자 프리뷰 버전을 사용해야 합니다. 요청을 인증하려면 API 키를 전달해야 합니다.

API 키를 만들려면 앱의 Google Cloud 프로젝트를 열고 다음을 수행합니다.

  1. Google Cloud 콘솔에서 메뉴 로 이동합니다. &gt; API 및 서비스 &gt; 사용자 인증 정보를 선택합니다.

    사용자 인증 정보로 이동

  2. 사용자 인증 정보 만들기 &gt;를 클릭합니다. API 키.
  3. 새 API 키가 표시됩니다.
    • 복사 를 클릭하여 앱 코드에서 사용할 API 키를 복사합니다. 또한 API 키는 'API 키'에서 찾을 수 있습니다. 섹션으로 이동합니다.
    • 키 제한을 클릭하여 고급 설정을 업데이트하고 사용을 제한합니다. 확인할 수 있습니다 자세한 내용은 API 키 제한사항 적용을 참고하세요.

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, discoveryServiceUrl='https://chat.googleapis.com/$discovery/rest?version=v1&labels=DEVELOPER_PREVIEW&key=API_KEY')
    
        # 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. 코드에서 다음을 바꿉니다.

    • API_KEY: Chat API의 서비스 엔드포인트를 빌드하기 위해 만든 API 키입니다.

    • SPACE: 스페이스 이름입니다. GCP 콘솔에서 spaces.list 메서드 Chat API 또는 스페이스의 URL에서 가져올 수 있습니다.

    • MEMBERSHIP: Chat API의 spaces.members.list 메서드에서 가져올 수 있는 멤버십 이름입니다.

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

    python3 chat_membership_update_to_manager_app.py

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

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

API 키 만들기

개발자 프리뷰 API 메서드를 호출하려면 API 검색 문서의 비공개 개발자 프리뷰 버전을 사용해야 합니다. 요청을 인증하려면 API 키를 전달해야 합니다.

API 키를 만들려면 앱의 Google Cloud 프로젝트를 열고 다음을 수행합니다.

  1. Google Cloud 콘솔에서 메뉴 로 이동합니다. &gt; API 및 서비스 &gt; 사용자 인증 정보를 선택합니다.

    사용자 인증 정보로 이동

  2. 사용자 인증 정보 만들기 &gt;를 클릭합니다. API 키.
  3. 새 API 키가 표시됩니다.
    • 복사 를 클릭하여 앱 코드에서 사용할 API 키를 복사합니다. 또한 API 키는 'API 키'에서 찾을 수 있습니다. 섹션으로 이동합니다.
    • 키 제한을 클릭하여 고급 설정을 업데이트하고 사용을 제한합니다. 확인할 수 있습니다 자세한 내용은 API 키 제한사항 적용을 참고하세요.

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

다음 예시에서는 다음을 사용하여 Chat API를 호출합니다. 앱 인증 role를 업데이트된 멤버십 속성을 지정하는 bodyROLE_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, discoveryServiceUrl='https://chat.googleapis.com/$discovery/rest?version=v1&labels=DEVELOPER_PREVIEW&key=API_KEY')
    
        # 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. 코드에서 다음을 바꿉니다.

    • API_KEY: 빌드를 위해 만든 API 키 Chat API의 서비스 엔드포인트입니다

    • SPACE: Chat API의 spaces.list 메서드 또는 스페이스의 URL에서 가져올 수 있는 스페이스 이름입니다.

    • MEMBERSHIP: 멤버십 이름으로, GCP 콘솔에서 spaces.members.list 메서드 채팅 API에서 지원됩니다.

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

    python3 chat_membership_update_to_member_app.py

Google Workspace 관리자로 멤버십 업데이트하기

Google Workspace 관리자인 경우 update()에 전화할 수 있습니다. Google Workspace 내 모든 스페이스의 멤버십을 업데이트하는 방법 사용할 수 있습니다

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

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

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