스페이스의 멤버 나열

이 가이드에서는 membership 리소스에서 list 메서드를 사용하는 방법을 설명합니다. 스페이스의 참여자를 페이지로 나눈 필터링 가능한 목록으로 나열할 수 있는 Google Chat API 몇 가지 옵션을 제공합니다 멤버십 등록 기준 앱 인증 채팅 앱에서 보유한 스페이스의 멤버십이 나열됩니다. 액세스할 수 있지만 다음을 포함한 채팅 앱 멤버십은 제외됩니다. 있습니다. 멤버십 등록 기준 사용자 인증 인증된 사용자가 액세스할 수 있는 스페이스의 멤버십이 나열됩니다.

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

기본 요건

Python

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

사용자 인증을 통해 스페이스의 멤버 나열

스페이스에 사용자, Google 그룹스, Chat 앱을 나열하려는 경우 액세스 권한이 있는 경우 요청에 다음을 전달합니다.

  • 다음으로 바꿉니다. 사용자 인증 chat.memberships.readonly 또는 chat.memberships 승인을 지정합니다. 범위를 제공합니다
  • 먼저 list 메서드membership 리소스.
  • Google 그룹스를 나열하려면 쿼리 매개변수 showGroupstrue로 설정합니다.

다음 예는 다음에 공개되는 Google 그룹, 사람, 앱 구성원을 나열합니다. 확인할 수 있습니다

Python

  1. 작업 디렉터리에 chat_member_list_user.py라는 파일을 만듭니다.
  2. chat_member_list_user.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.readonly"]
    
    def main():
        '''
        Authenticates with Chat API via user credentials,
        then lists Google Group, human, and app members in a 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().members().list(
    
            # The space for which to list memberships.
            parent = 'spaces/SPACE',
    
            # Set this parameter to list Google Groups.
            showGroups = 'true'
    
        ).execute()
    
        # Prints the list of memberships.
        print(result)
    
    if __name__ == '__main__':
        main()
    
  3. 코드에서 SPACE을 공백 이름으로 바꿉니다. GCP 콘솔에서 spaces.list 메서드 Chat API 또는 스페이스의 URL에서 가져올 수 있습니다.

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

    python3 chat_member_list_user.py
    

Google Chat API는 지정합니다.

앱 인증이 있는 스페이스의 멤버 나열

스페이스에 사용자와 채팅 앱을 표시하려면 다음 단계를 따르세요. 액세스할 수 있는 경우 요청에 다음을 전달합니다.

  • 다음으로 바꿉니다. 앱 인증 chat.bot 승인 범위를 지정합니다.
  • 먼저 list 메서드member 리소스.
  • Google 그룹스를 나열하려면 쿼리 매개변수 showGroupstrue로 설정합니다.

다음 예에는 스페이스 관리자가 아닌 다음 사용자에게 표시되는 사용자 스페이스 구성원 목록이 나와 있습니다. 채팅 앱:

Python

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

    from google.oauth2 import service_account
    from apiclient.discovery import build
    
    # Specify required scopes.
    SCOPES = ['https://www.googleapis.com/auth/chat.bot']
    
    # Specify service account details.
    CREDENTIALS = (
        service_account.Credentials.from_service_account_file('credentials.json')
        .with_scopes(SCOPES)
    )
    
    # Build the URI and authenticate with the service account.
    chat = build('chat', 'v1', credentials=CREDENTIALS)
    
    # Use the service endpoint to call Chat API.
    result = chat.spaces().members().list(
    
            # The space for which to list memberships.
            parent = 'spaces/SPACE',
    
            # An optional filter that returns only human space members.
            filter = 'member.type = "HUMAN" AND role = "ROLE_MEMBER"'
    
        ).execute()
    
    print(result)
    
  3. 코드에서 SPACE을 공백 이름으로 바꿉니다. GCP 콘솔에서 spaces.list 메서드 Chat API 또는 스페이스의 URL에서 가져올 수 있습니다.

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

    python3 chat_member_list_app.py
    

Google Chat API는 사용자 스페이스 구성원 (스페이스 제외)의 목록을 반환합니다. 관리자)가 있어야 합니다.

페이지로 나누기 맞춤설정 또는 목록 필터링

멤버십을 나열하려면 다음 쿼리 매개변수를 나열된 멤버십의 페이지로 나누기를 맞춤설정하거나 필터링합니다.

  • pageSize: 반환할 최대 멤버십 수입니다. 서비스는 이 값보다 적은 값을 반환합니다. 지정하지 않으면 최대 100개의 공백이 반환합니다. 최댓값은 1,000입니다. 1,000을 초과하는 값은 자동으로 1,000으로 변경되었습니다.
  • pageToken: 이전 스페이스 목록 호출에서 수신된 페이지 토큰입니다. 후속 페이지를 검색하려면 이 토큰을 제공하세요. 페이지로 나누기 시 필터 값이 페이지 토큰을 제공한 호출과 일치해야 합니다. 예기치 않은 결과가 발생할 수 있습니다
  • filter: 쿼리 필터입니다. 요구사항 사용자 인증 지원되는 쿼리 세부정보는 다음을 참조하세요. spaces.members.list 메서드