קל לארגן דפים בעזרת אוספים
אפשר לשמור ולסווג תוכן על סמך ההעדפות שלך.
במדריך הזה מוסבר איך להשתמש בשיטה get() במשאב SpaceReadState של Google Chat API כדי לקבל פרטים על סטטוס הקריאה של משתמש במרחב. כדי לקבל את סטטוס הקריאה של הודעה בשרשור, אפשר לעיין במאמר קבלת פרטים על סטטוס הקריאה של שרשור אצל משתמש.
SpaceReadState המשאב הוא משאב יחיד שמייצג פרטים על ההודעה האחרונה שמשתמש מסוים קרא במרחב ב-Google Chat.
יצירת פרטי כניסה של מזהה לקוח OAuth לאפליקציה למחשב. כדי להריץ את הדוגמה במדריך הזה, צריך לשמור את פרטי הכניסה כקובץ JSON בשם credentials.json בספרייה המקומית.
כדי לקבל הנחיות, מבצעים את השלבים להגדרת הסביבה במדריך למתחילים הזה.
כדי לקבל פרטים על סטטוס הקריאה של משתמש במרחב, צריך לכלול בבקשה את הפרטים הבאים:
מציינים את היקף ההרשאות של chat.users.readstate או chat.users.readstate.readonly.
מתקשרים לשיטה
GetSpaceReadState()
ומעבירים את name של מצב הקריאה של המרחב כדי לקבל את המזהה של המשתמש או הכינוי ואת מזהה המרחב. אפשר לקבל את סטטוס הקריאה של המשתמש שקורא את הנתונים, על ידי הגדרת אחת מהאפשרויות הבאות:
הכינוי 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.
[[["התוכן קל להבנה","easyToUnderstand","thumb-up"],["התוכן עזר לי לפתור בעיה","solvedMyProblem","thumb-up"],["סיבה אחרת","otherUp","thumb-up"]],[["חסרים לי מידע או פרטים","missingTheInformationINeed","thumb-down"],["התוכן מורכב מדי או עם יותר מדי שלבים","tooComplicatedTooManySteps","thumb-down"],["התוכן לא עדכני","outOfDate","thumb-down"],["בעיה בתרגום","translationIssue","thumb-down"],["בעיה בדוגמאות/בקוד","samplesCodeIssue","thumb-down"],["סיבה אחרת","otherDown","thumb-down"]],["עדכון אחרון: 2025-09-10 (שעון UTC)."],[[["\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,[]]