جزئیات مربوط به وضعیت خواندن فضای کاربر را دریافت کنید
با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
این راهنما نحوه استفاده از متد get() را در منبع SpaceReadState در Google Chat API برای دریافت جزئیات در مورد وضعیت خواندن کاربر در یک فاصله توضیح میدهد. برای دریافت وضعیت خواندن یک پیام در یک رشته پیام، به دریافت جزئیات در مورد وضعیت خواندن رشته کاربر مراجعه کنید.
منبع SpaceReadState یک منبع تکی است که جزئیات مربوط به آخرین پیام خوانده شده کاربر مشخص شده را در فضای چت Google نشان می دهد.
وضعیت خواندن فضای کاربر تماس گیرنده را دریافت کنید
برای دریافت جزئیات در مورد وضعیت خواندن کاربر در یک فاصله، موارد زیر را در درخواست خود بگنجانید:
محدوده مجوز chat.users.readstate یا chat.users.readstate.readonly را مشخص کنید.
متد GetSpaceReadState() را فراخوانی کنید و name حالت خواندن فاصله را ارسال کنید تا به این ترتیب یک شناسه کاربری یا نام مستعار و یک ID فاصله دریافت کنید. دریافت وضعیت خواندن فضا فقط از دریافت وضعیت خواندن کاربر تماسگیرنده پشتیبانی میکند که با تنظیم یکی از موارد زیر میتوان آن را تعیین کرد:
me مستعار من برای مثال، users/me/spaces/ SPACE /spaceReadState .
آدرس ایمیل کاربر تماس گیرنده Workspace. به عنوان مثال، users/user@example.com/spaces/ SPACE /spaceReadState .
شناسه کاربری کاربر تماس گیرنده. به عنوان مثال، users/ USER /spaces/ SPACE /spaceReadState .
مثال زیر وضعیت خواندن فضای کاربر فراخوان را دریافت می کند:
import{createClientWithUserCredentials}from'./authentication-utils.js';constUSER_AUTH_OAUTH_SCOPES=['https://www.googleapis.com/auth/chat.users.readstate.readonly'];// This sample shows how to get the space read state for the calling userasyncfunctionmain(){// Create a clientconstchatClient=awaitcreateClientWithUserCredentials(USER_AUTH_OAUTH_SCOPES);// Initialize request argument(s)constrequest={// Replace SPACE_NAME herename:'users/me/spaces/SPACE_NAME/spaceReadState'};// Make the requestconstresponse=awaitchatClient.getSpaceReadState(request);// Handle the responseconsole.log(response);}main().catch(console.error);
برای اجرای این نمونه، SPACE_NAME با شناسه name فضا جایگزین کنید. شما می توانید شناسه را با فراخوانی متد ListSpaces() یا از URL فضا بدست آورید.
Google Chat API وضعیت خواندن فضای مشخص شده را دریافت می کند و نمونه ای از SpaceReadState را برمی گرداند.
تاریخ آخرین بهروزرسانی 2025-05-30 بهوقت ساعت هماهنگ جهانی.
[null,null,["تاریخ آخرین بهروزرسانی 2025-05-30 بهوقت ساعت هماهنگ جهانی."],[[["\u003cp\u003eThis guide explains how to use the \u003ccode\u003eget()\u003c/code\u003e method to retrieve a user's read state within a Google Chat space using the Google Chat API.\u003c/p\u003e\n"],["\u003cp\u003eYou need a Google Workspace account and a configured Google Cloud project with the Google Chat API enabled to use this functionality.\u003c/p\u003e\n"],["\u003cp\u003eThe guide provides instructions and code samples (Node.js) to retrieve the calling user's space read state using the \u003ccode\u003eGetSpaceReadState()\u003c/code\u003e method.\u003c/p\u003e\n"],["\u003cp\u003eTo get the read state, you need to specify the appropriate authorization scope and provide the space name in the request.\u003c/p\u003e\n"],["\u003cp\u003eFor message-specific read states within a thread, refer to the separate guide on getting thread read states.\u003c/p\u003e\n"]]],["To retrieve a user's read state in a Google Chat space, use the `get()` method on the `SpaceReadState` resource. First, ensure you have a Google Workspace account, set up your environment with Node.js, and have appropriate OAuth credentials. Then, specify the `chat.users.readstate` or `chat.users.readstate.readonly` scope, and call `GetSpaceReadState()`, providing the space read state's `name`, including the user's ID or alias and the space ID. This returns a `SpaceReadState` instance.\n"],null,["# Get details about a user's space read state\n\nThis guide explains how to use the\n[`get()`](/workspace/chat/api/reference/rpc/google.chat.v1#google.chat.v1.ChatService.GetSpaceReadState)\nmethod on the `SpaceReadState` resource of the Google Chat API to get details about\na user's read state within a space. To get the read state of a message in a\nmessage thread, see\n[Get details about a user's thread read state](/workspace/chat/get-thread-read-state).\n\nThe\n[`SpaceReadState` resource](/workspace/chat/api/reference/rpc/google.chat.v1#google.chat.v1.SpaceReadState)\nis a singleton resource that represents details about a\nspecified user's last read message in a Google Chat space.\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 read state\n---------------------------------------\n\nTo get details about a user's read state within a space, include the following\nin your request:\n\n- Specify the `chat.users.readstate` or `chat.users.readstate.readonly` authorization scope.\n- Call the [`GetSpaceReadState()`](/workspace/chat/api/reference/rpc/google.chat.v1#google.chat.v1.ChatService.GetSpaceReadState) method, passing the `name` of the space read state to get which includes a user ID or alias and a space ID. Getting space read state only supports getting the read state of the calling user, which can be specified by setting one of the following:\n - The `me` alias. For example, `users/me/spaces/`\u003cvar translate=\"no\"\u003eSPACE\u003c/var\u003e`/spaceReadState`.\n - The calling user's Workspace email address. For example, `users/user@example.com/spaces/`\u003cvar translate=\"no\"\u003eSPACE\u003c/var\u003e`/spaceReadState`.\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`/spaceReadState`.\n\nThe following example gets the calling user's space read state: \n\n### Node.js\n\nchat/client-libraries/cloud/get-space-read-state-user-cred.js \n[View on GitHub](https://github.com/googleworkspace/node-samples/blob/main/chat/client-libraries/cloud/get-space-read-state-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.readstate.readonly'];\n\n// This sample shows how to get the space read state 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)\n const request = {\n // Replace SPACE_NAME here\n name: 'users/me/spaces/SPACE_NAME/spaceReadState'\n };\n\n // Make the request\n const response = await chatClient.getSpaceReadState(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_NAME\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 read state and returns\nan instance of\n[`SpaceReadState`](/workspace/chat/api/reference/rpc/google.chat.v1#google.chat.v1.SpaceReadState).\n\nRelated topics\n--------------\n\n- [Update the calling user's space read state](/workspace/chat/update-space-read-state).\n- [Get the calling user's thread read state](/workspace/chat/get-thread-read-state)."]]