メンバーシップの詳細を確認する

このガイドでは、membership リソースで get メソッドを使用する方法について説明します を使用して、スペースのメンバーシップに関する詳細情報を取得できます。

Membership リソース 人間のユーザーまたは Google Chat アプリのどちらが招待されているかを表します。 その場から離れることがなくなります。

認証 アプリの認証 Chat アプリは、スペースのメンバーシップを取得できるようになります。 (たとえば、そのユーザーがメンバーになっているスペースなど)にしかアクセスできず、 Chat アプリのメンバーシップ(独自のものを含む)。認証中 ユーザー認証 認証されたユーザーがアクセスできるスペースのメンバーシップを返します。

前提条件

Python

  • Python 3.6 以降
  • pip パッケージ管理ツール
  • 最新の Google クライアント ライブラリ。インストールまたは更新する手順は次のとおりです。 コマンドライン インターフェースで次のコマンドを実行します。
    pip3 install --upgrade google-api-python-client google-auth-oauthlib
    

メンバーシップの詳細を確認する

Google Chat でメンバーシップの詳細を確認するには、 request:

  • あり app authentication: chat.bot 承認スコープ。あり ユーザー認証chat.memberships.readonly または chat.memberships 承認を指定する あります。最も制限の厳しいスコープを選択することをおすすめします。 アプリが機能できるようになります
  • 呼び出し get メソッド 日付 membership リソース
  • 取得するには、メンバーシップの name を渡します。メンバーシップ名を アクセスする方法を紹介します。

メンバーシップの登録方法 ユーザー認証:

Python

  1. 作業ディレクトリに、chat_membership_get.py という名前のファイルを作成します。
  2. chat_membership_get.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 gets details about a 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().get(
    
            # The membership to get.
            #
            # 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.
            name='spaces/SPACE/members/MEMBER'
    
        ).execute()
    
        # Prints details about the membership.
        print(result)
    
    if __name__ == '__main__':
        main()
    
  3. コードの次のように置き換えます。

  4. 作業ディレクトリでサンプルをビルドして実行します。

    python3 chat_membership_get.py
    

Chat API は、メッセージに対して membership 詳細情報が含まれます。