با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
این راهنما نحوه استفاده از متد list() را در منبع SpaceEvent در Google Chat API برای فهرست کردن تغییرات منابع در یک فضا توضیح میدهد.
منبع SpaceEvent نشاندهنده تغییر در فضای هدف، از جمله منابع فرزند فضا مانند پیامها، واکنشها و عضویتها است. برای اطلاعات بیشتر در مورد لیست انواع رویداد و بارهای رویداد پشتیبانی شده، به فیلدهای eventType و payload در اسناد مرجع منبع SpaceEvent مراجعه کنید.
شما می توانید رویدادها را تا 28 روز قبل از زمان درخواست لیست کنید. سرور رویدادهایی را برمی گرداند که حاوی جدیدترین نسخه منبع آسیب دیده هستند. برای مثال، اگر رویدادهای مربوط به اعضای جدید فضایی را فهرست کنید، سرور منابع Membership را که حاوی آخرین جزئیات عضویت است، برمیگرداند. اگر اعضای جدید در طول دوره درخواستی حذف شوند، بار رویداد حاوی یک منبع Membership خالی است.
برای فراخوانی این روش، باید از احراز هویت کاربر استفاده کنید. برای فهرست کردن رویدادها از یک فضا، کاربر احراز هویت شده باید عضوی از فضا باشد.
برای فهرست کردن رویدادهای فضایی از فضای چت، موارد زیر را در درخواست خود ارسال کنید:
یک یا چند حوزه مجوز را برای پشتیبانی از هر نوع رویداد در درخواست خود مشخص کنید. به عنوان بهترین روش، محدودترین محدوده را انتخاب کنید که همچنان به برنامه شما اجازه عملکرد می دهد. برای انتخاب محدوده، به نمای کلی احراز هویت و مجوز مراجعه کنید.
متد ListSpaceEvents() را فراخوانی کنید و filter انواع رویداد را به لیست منتقل کنید. شما باید حداقل یک نوع رویداد را مشخص کنید، و همچنین می توانید بر اساس تاریخ فیلتر کنید. برای لیستی از انواع رویدادهای پشتیبانی شده، به قسمت eventType در مستندات مرجع منبع SpaceEvent مراجعه کنید.
مثال زیر رویدادهای مربوط به عضویتها و پیامهای جدید را در یک فضا فهرست میکند:
import{createClientWithUserCredentials}from'./authentication-utils.js';// Authorization scopes based on the event typesconstUSER_AUTH_OAUTH_SCOPES=['https://www.googleapis.com/auth/chat.memberships.readonly','https://www.googleapis.com/auth/chat.messages.readonly'];// This sample shows how to list space events with user credentialasyncfunctionmain(){// Create a clientconstchatClient=awaitcreateClientWithUserCredentials(USER_AUTH_OAUTH_SCOPES);// Initialize request argument(s)constrequest={// Replace SPACE_NAME hereparent:'spaces/SPACE_NAME',// A required filter. Filters events about new memberships and messagesfilter:'eventTypes:"google.workspace.chat.membership.v1.created" OR eventTypes:"google.workspace.chat.message.v1.created"'};// Make the requestconstpageResult=chatClient.listSpaceEventsAsync(request);// Handle the response. Iterating over pageResult will yield results and// resolve additional pages automatically.forawait(constresponseofpageResult){console.log(response);}}main().catch(console.error);
برای اجرای این نمونه، SPACE_NAME با شناسه name فضا جایگزین کنید. شما می توانید شناسه را با فراخوانی متد ListSpaces() یا از URL فضا بدست آورید.
تاریخ آخرین بهروزرسانی 2025-08-04 بهوقت ساعت هماهنگ جهانی.
[null,null,["تاریخ آخرین بهروزرسانی 2025-08-04 بهوقت ساعت هماهنگ جهانی."],[[["\u003cp\u003eThis guide explains how to use the \u003ccode\u003elist()\u003c/code\u003e method to list changes to resources in a Google Chat space using the \u003ccode\u003eSpaceEvent\u003c/code\u003e resource.\u003c/p\u003e\n"],["\u003cp\u003eYou can list events up to 28 days prior, retrieving the most recent version of affected resources, and must authenticate with user credentials and be a space member.\u003c/p\u003e\n"],["\u003cp\u003eTo call this method, specify authorization scopes for desired event types and use the \u003ccode\u003eListSpaceEvents()\u003c/code\u003e method with a filter to specify event types and date ranges.\u003c/p\u003e\n"],["\u003cp\u003eThe provided Node.js code sample demonstrates listing events for new memberships and messages within a space, requiring replacement of \u003ccode\u003eSPACE_NAME\u003c/code\u003e with the space's ID.\u003c/p\u003e\n"]]],["This guide details how to use the `list()` method on the `SpaceEvent` resource within the Google Chat API to track changes in a space, such as new memberships and messages. To use, authenticate as a space member and specify the desired event types using the `filter` parameter when calling `ListSpaceEvents()`. The method returns the latest resource versions, up to 28 days prior, with the ability to filter by date. An example is provided showing how to filter events about new memberships and messages.\n"],null,["# List events from a Google Chat space\n\nThis guide explains how to use the\n[`list()`](/workspace/chat/api/reference/rpc/google.chat.v1#google.chat.v1.ChatService.ListSpaceEvents)\nmethod on the `SpaceEvent` resource of the Google Chat API to list changes to\nresources in a space.\n\nThe\n[`SpaceEvent` resource](/workspace/chat/api/reference/rpc/google.chat.v1#google.chat.v1.SpaceEvent)\nrepresents a change to the target space, including child resources of the space\nsuch as messages, reactions, and memberships. For more information about the\nlist of event types and event payloads supported, see the\n[`eventType`](/workspace/chat/api/reference/rpc/google.chat.v1#google.chat.v1.SpaceEvent.FIELDS.string.google.chat.v1.SpaceEvent.event_type)\nand\n[`payload`](/workspace/chat/api/reference/rpc/google.chat.v1#google.chat.v1.SpaceEvent.FIELDS.oneof_payload)\nfields of the `SpaceEvent` resource reference documentation.\n\nYou can list events up to 28 days before the time of the request. The server\nreturns events that contain the most recent version of the affected resource.\nFor example, if you list events about new space members, the server returns\n`Membership` resources that contain the latest membership details. If new\nmembers were removed during the requested period, the event payload contains an\nempty `Membership` resource.\n\nTo call this method, you must use\n[user authentication](/workspace/chat/authenticate-authorize-chat-user). To list\nevents from a space, the authenticated user must be a member of the 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\nList space events\n-----------------\n\nTo list space events from a Chat space, pass the following in\nyour request:\n\n- Specify one or more authorization scopes to support each event type in your\n request. As a best practice, choose the most restrictive scope that still\n allows your app to function. To choose a scope, see the\n [Authentication and authorization overview](/workspace/chat/authenticate-authorize#space-events).\n\n- Call the\n [`ListSpaceEvents()`](/workspace/chat/api/reference/rpc/google.chat.v1#google.chat.v1.ChatService.ListSpaceEvents)\n method, passing the `filter` of event types to list.\n You must specify at least one event type, and you can also filter by date.\n For a list of supported event types, see the\n [`eventType` field of the `SpaceEvent` resource](/workspace/chat/api/reference/rpc/google.chat.v1#google.chat.v1.SpaceEvent.FIELDS.string.google.chat.v1.SpaceEvent.event_type)\n reference documentation.\n\nThe following example lists events about new memberships and messages in a\nspace: \n\n### Node.js\n\nchat/client-libraries/cloud/list-space-events-user-cred.js \n[View on GitHub](https://github.com/googleworkspace/node-samples/blob/main/chat/client-libraries/cloud/list-space-events-user-cred.js) \n\n```javascript\nimport {createClientWithUserCredentials} from './authentication-utils.js';\n\n// Authorization scopes based on the event types\nconst USER_AUTH_OAUTH_SCOPES = [\n 'https://www.googleapis.com/auth/chat.memberships.readonly',\n 'https://www.googleapis.com/auth/chat.messages.readonly'\n];\n\n// This sample shows how to list space events with user credential\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 parent: 'spaces/SPACE_NAME',\n // A required filter. Filters events about new memberships and messages\n filter: 'eventTypes:\"google.workspace.chat.membership.v1.created\" OR eventTypes:\"google.workspace.chat.message.v1.created\"'\n };\n\n // Make the request\n const pageResult = chatClient.listSpaceEventsAsync(request);\n\n // Handle the response. Iterating over pageResult will yield results and\n // resolve additional pages automatically.\n for await (const response of pageResult) {\n console.log(response);\n }\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 Chat API returns a list of\n[paginated list of space events](/workspace/chat/api/reference/rpc/google.chat.v1#listspaceeventsresponse)\nabout new memberships and messages.\n\nRelated topics\n--------------\n\n- [Work with events from Google Chat](/workspace/chat/events-overview)\n- [Get details about a space event](/workspace/chat/get-space-event)"]]