이 가이드에서는 Google Chat API의 SpaceEvent 리소스에서 list() 메서드를 사용하여 스페이스의 리소스 변경사항을 나열하는 방법을 설명합니다.
SpaceEvent 리소스는 메시지, 반응, 멤버십과 같은 스페이스의 하위 리소스를 포함하여 타겟 스페이스의 변경사항을 나타냅니다. 지원되는 이벤트 유형 및 이벤트 페이로드 목록에 대한 자세한 내용은 SpaceEvent 리소스 참조 문서의 eventType 및 payload 필드를 참고하세요.
요청 시간 최대 28일 전의 이벤트를 나열할 수 있습니다. 서버는 영향을 받는 리소스의 최신 버전이 포함된 이벤트를 반환합니다.
예를 들어 새 스페이스 구성원에 관한 이벤트를 나열하면 서버는 최신 멤버십 세부정보가 포함된 Membership 리소스를 반환합니다. 요청된 기간 동안 새 회원이 삭제된 경우 이벤트 페이로드에 빈 Membership 리소스가 포함됩니다.
이 메서드를 호출하려면 사용자 인증을 사용해야 합니다. 스페이스의 이벤트를 나열하려면 인증된 사용자가 스페이스의 구성원이어야 합니다.
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에서 가져온 ID로 바꿉니다.
ListSpaces() 메서드를 호출하거나 스페이스의 URL에서 ID를 가져올 수 있습니다.
[null,null,["최종 업데이트: 2025-08-04(UTC)"],[[["\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)"]]