ユーザーのスペースの通知設定を取得する

このガイドでは、Google Chat API の SpaceNotificationSetting リソースで get() メソッドを使用して、ユーザーのスペースの通知設定を取得する方法について説明します。

SpaceNotificationSetting リソースは、指定されたユーザーのスペース通知設定の詳細を表すシングルトン リソースです。

前提条件

Node.js

呼び出し元のユーザーのスペースの通知設定を取得する

ユーザーのスペースの通知設定の詳細を取得するには、リクエストに次の情報を含めます。

  • chat.users.spacesettings 認可スコープを指定します。
  • GetSpaceNotificationSetting() メソッドを呼び出し、スペース通知設定の name を渡して、ユーザー ID またはエイリアスとスペース ID を含むものを取得します。取得できるのは、発信元のユーザーの通知設定のみです。設定を指定するには、次のいずれかを使用します。
    • me エイリアス。例: users/me/spaces/SPACE_ID/spaceNotificationSetting
    • 呼び出し元のユーザーの Google Workspace メールアドレス。例: users/user@example.com/spaces/SPACE_ID/spaceNotificationSetting
    • 呼び出し元のユーザーのユーザー ID。例: users/USER/spaces/SPACE/spaceNotificationSetting

次の例は、呼び出し元のユーザーのスペースの通知設定を取得します。

Node.js
chat/client-libraries/cloud/get-space-notification-setting-user-cred.js
import {createClientWithUserCredentials} from './authentication-utils.js';

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

// This sample shows how to get the space notification setting for the calling user
async function main() {
  // Create a client
  const chatClient = await createClientWithUserCredentials(USER_AUTH_OAUTH_SCOPES);

  // Initialize request argument(s), replace the SPACE_NAME with an actual space name.
  const request = {
    name : 'users/me/spaces/SPACE_NAME/spaceNotificationSetting'
  };

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

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

main().catch(console.error);

このサンプルを実行するには、SPACE_ID をスペースの name の ID に置き換えます。ID は、ListSpaces() メソッドを呼び出すか、スペースの URL から取得できます。

Google Chat API は、指定されたスペースの通知設定を取得し、SpaceNotificationSetting のインスタンスを返します。