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-02-14。"],[[["This guide explains how to use the `get()` method to retrieve a user's read state within a Google Chat space using the Google Chat API."],["You need a Google Workspace account and a configured Google Cloud project with the Google Chat API enabled to use this functionality."],["The guide provides instructions and code samples (Node.js) to retrieve the calling user's space read state using the `GetSpaceReadState()` method."],["To get the read state, you need to specify the appropriate authorization scope and provide the space name in the request."],["For message-specific read states within a thread, refer to the separate guide on getting thread read states."]]],["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"]]