Xem chế độ cài đặt thông báo của người dùng về không gian
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Hướng dẫn này giải thích cách sử dụng phương thức get() trên tài nguyên SpaceNotificationSetting của API Google Chat để lấy chế độ cài đặt thông báo về không gian của người dùng.
Tài nguyên SpaceNotificationSetting là một tài nguyên singleton đại diện cho thông tin chi tiết về chế độ cài đặt thông báo của không gian của một người dùng cụ thể.
Tạo thông tin xác thực mã ứng dụng khách OAuth cho ứng dụng dành cho máy tính. Để chạy mẫu trong hướng dẫn này, hãy lưu thông tin xác thực dưới dạng tệp JSON có tên credentials.json vào thư mục cục bộ.
Để được hướng dẫn, hãy hoàn thành các bước thiết lập môi trường trong bài viết
bắt đầu nhanh này.
Lấy chế độ cài đặt thông báo của không gian của người dùng gọi
Để biết thông tin chi tiết về chế độ cài đặt thông báo của người dùng về không gian, hãy thêm những thông tin sau vào yêu cầu của bạn:
Chỉ định phạm vi uỷ quyền chat.users.spacesettings.
Gọi phương thức GetSpaceNotificationSetting(), truyền name của chế độ cài đặt thông báo của không gian để nhận thông báo bao gồm mã nhận dạng người dùng hoặc bí danh và mã nhận dạng không gian. Bạn chỉ có thể nhận được chế độ cài đặt thông báo cho người dùng gọi. Để chỉ định chế độ cài đặt, hãy sử dụng một trong những cách sau:
Bí danh me. Ví dụ: users/me/spaces/SPACE_ID/spaceNotificationSetting.
Địa chỉ email Google Workspace của người dùng gọi. Ví dụ: users/user@example.com/spaces/SPACE_ID/spaceNotificationSetting.
Mã nhận dạng người dùng của người dùng gọi. Ví dụ: users/USER/spaces/SPACE/spaceNotificationSetting.
Ví dụ sau đây lấy chế độ cài đặt thông báo của không gian của người dùng gọi:
import{createClientWithUserCredentials}from'./authentication-utils.js';constUSER_AUTH_OAUTH_SCOPES=['https://www.googleapis.com/auth/chat.users.spacesettings'];// This sample shows how to get the space notification setting for the calling userasyncfunctionmain(){// Create a clientconstchatClient=awaitcreateClientWithUserCredentials(USER_AUTH_OAUTH_SCOPES);// Initialize request argument(s), replace the SPACE_NAME with an actual space name.constrequest={name:'users/me/spaces/SPACE_NAME/spaceNotificationSetting'};// Make the requestconstresponse=awaitchatClient.getSpaceNotificationSetting(request);// Handle the responseconsole.log(response);}main().catch(console.error);
Để chạy mẫu này, hãy thay thế SPACE_ID bằng mã nhận dạng từ name của không gian.
Bạn có thể lấy mã nhận dạng bằng cách gọi phương thức ListSpaces() hoặc từ URL của không gian.
API Google Chat sẽ lấy chế độ cài đặt thông báo của không gian đã chỉ định và trả về một thực thể của SpaceNotificationSetting.
[null,null,["Cập nhật lần gần đây nhất: 2025-05-30 UTC."],[],[],null,["# Get a user's space notification settings\n\nThis guide explains how to use the\n[`get()`](/workspace/chat/api/reference/rpc/google.chat.v1#google.chat.v1.ChatService.GetSpaceNotificationSetting)\nmethod on the `SpaceNotificationSetting` resource of the Google Chat API to get\na user's space notification settings.\n\nThe\n[`SpaceNotificationSetting` resource](/workspace/chat/api/reference/rpc/google.chat.v1#google.chat.v1.SpaceNotificationSetting)\nis a singleton resource that represents details about a specified user's space\nnotification settings.\n\nPrerequisites\n-------------\n\n\n### Node.js\n\n- A Business or Enterprise [Google Workspace](https://support.google.com/a/answer/6043576) account with access to [Google Chat](https://workspace.google.com/products/chat/).\n\n\u003c!-- --\u003e\n\n- Set up your environment:\n - [Create a Google Cloud project](/workspace/guides/create-project).\n - [Configure the OAuth consent screen](/workspace/guides/configure-oauth-consent).\n - [Enable and configure the Google Chat API](/workspace/chat/configure-chat-api) with a name, icon, and description for your Chat app.\n - Install the Node.js [Cloud Client Library](/workspace/chat/libraries?tab=nodejs#cloud-client-libraries).\n - [Create OAuth client ID credentials](/workspace/chat/authenticate-authorize-chat-user#step-2:) for a desktop application. To run the sample in this guide, save the credentials as a JSON file named `credentials.json` to your local directory.\n\n For guidance, complete the steps for setting up your environment in this [quickstart](/workspace/chat/api/guides/quickstart/nodejs\n #set-up-environment).\n- [Choose an authorization scope](/workspace/chat/authenticate-authorize#asynchronous-chat-calls) that supports user authentication.\n\n\n| The code samples in this page use the gRPC API interface with the Google Cloud client libraries. Alternatively, you can use the REST API interface. For more information about the gRPC and REST interfaces, see [Google Chat API overview](/workspace/chat/api/reference).\n\n\u003cbr /\u003e\n\nGet the calling user's space notification settings\n--------------------------------------------------\n\nTo get details about a user's space notification settings, include the following\nin your request:\n\n- Specify the `chat.users.spacesettings` authorization scope.\n- Call the [`GetSpaceNotificationSetting()`](/workspace/chat/api/reference/rpc/google.chat.v1#google.chat.v1.ChatService.GetSpaceNotificationSetting) method, passing the `name` of the space notification settings to get which includes a user ID or alias and a space ID. You can only get notification settings for the calling user. To specify the settings, use one of the following:\n - The `me` alias. For example, `users/me/spaces/`\u003cvar translate=\"no\"\u003eSPACE_ID\u003c/var\u003e`/spaceNotificationSetting`.\n - The calling user's Google Workspace email address. For example, `users/user@example.com/spaces/`\u003cvar translate=\"no\"\u003eSPACE_ID\u003c/var\u003e`/spaceNotificationSetting`.\n - The calling user's user ID. For example, `users/`\u003cvar translate=\"no\"\u003eUSER\u003c/var\u003e`/spaces/`\u003cvar translate=\"no\"\u003eSPACE\u003c/var\u003e`/spaceNotificationSetting`.\n\nThe following example gets the calling user's space notification settings: \n\n### Node.js\n\nchat/client-libraries/cloud/get-space-notification-setting-user-cred.js \n[View on GitHub](https://github.com/googleworkspace/node-samples/blob/main/chat/client-libraries/cloud/get-space-notification-setting-user-cred.js) \n\n```javascript\nimport {createClientWithUserCredentials} from './authentication-utils.js';\n\nconst USER_AUTH_OAUTH_SCOPES = ['https://www.googleapis.com/auth/chat.users.spacesettings'];\n\n// This sample shows how to get the space notification setting for the calling user\nasync function main() {\n // Create a client\n const chatClient = await createClientWithUserCredentials(USER_AUTH_OAUTH_SCOPES);\n\n // Initialize request argument(s), replace the SPACE_NAME with an actual space name.\n const request = {\n name : 'users/me/spaces/SPACE_NAME/spaceNotificationSetting'\n };\n\n // Make the request\n const response = await chatClient.getSpaceNotificationSetting(request);\n\n // Handle the response\n console.log(response);\n}\n\nmain().catch(console.error);\n```\n\nTo run this sample, replace \u003cvar translate=\"no\"\u003eSPACE_ID\u003c/var\u003e with the ID from\nthe space's\n[`name`](/workspace/chat/api/reference/rpc/google.chat.v1#google.chat.v1.Space.FIELDS.string.google.chat.v1.Space.name).\nYou can obtain the ID by calling the\n[`ListSpaces()`](/workspace/chat/api/reference/rpc/google.chat.v1#google.chat.v1.ChatService.ListSpaces)\nmethod or from the space's URL.\n\nThe Google Chat API gets the specified space notification settings and returns\nan instance of\n[`SpaceNotificationSetting`](/workspace/chat/api/reference/rpc/google.chat.v1#google.chat.v1.SpaceNotificationSetting).\n\nRelated topics\n--------------\n\n- [Update the calling user's space notification setting](/workspace/chat/update-space-notification-setting)."]]