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 中的 ID。您可以通过调用 ListSpaces() 方法或从聊天室的网址中获取此 ID。
[null,null,["最后更新时间 (UTC):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,[]]