Ottenere dettagli su un evento dello spazio di Google Chat
Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Questa guida spiega come utilizzare il metodo
get()
nella risorsa SpaceEvent dell'API Google Chat per ottenere dettagli su
un evento da uno spazio Google Chat.
La
risorsa SpaceEvent
rappresenta una modifica a uno spazio o alle relative risorse secondarie, come messaggi,
reazioni e iscrizioni. Per scoprire di più sui tipi di eventi supportati, consulta il
campo eventType della risorsa SpaceEvent
nella documentazione di riferimento.
Puoi richiedere eventi fino a 28 giorni prima dell'ora della richiesta. L'evento
contiene la versione più recente della risorsa modificata. Ad esempio, se
richiedi un evento relativo a un nuovo messaggio, ma il messaggio è stato aggiornato in un secondo momento, il
server restituisce la risorsa Message aggiornata nel payload dell'evento.
Per chiamare questo metodo, devi utilizzare
l'autenticazione utente. Per ottenere
un evento, l'utente autenticato deve essere membro dello spazio in cui si è verificato
l'evento.
Crea le credenziali dell'ID client OAuth per un'applicazione desktop. Per eseguire l'esempio in questa
guida, salva le credenziali come file JSON denominato credentials.json nella
directory locale.
Per indicazioni, completa i passaggi per configurare l'ambiente in questa
guida rapida.
Per ottenere dettagli su un evento dello spazio in Google Chat, passa quanto segue nella tua
richiesta:
Specifica un ambito di autorizzazione che supporti il tipo di evento nella richiesta.
Come best practice, scegli l'ambito più restrittivo che consenta comunque alla tua
app di funzionare.
Chiama il metodo
GetSpaceEvent(), passando l'name dell'evento dello spazio da recuperare.
L'esempio seguente recupera un evento dello spazio:
import{createClientWithUserCredentials}from'./authentication-utils.js';// Replace SCOPE_NAME here with an authorization scope based on the event typeconstUSER_AUTH_OAUTH_SCOPES=['SCOPE_NAME'];// This sample shows how to get space event with user credentialasyncfunctionmain(){// Create a clientconstchatClient=awaitcreateClientWithUserCredentials(USER_AUTH_OAUTH_SCOPES);// Initialize request argument(s)constrequest={// Replace SPACE_NAME and SPACE_EVENT_NAME herename:'spaces/SPACE_NAME/spaceEvents/SPACE_EVENT_NAME'};// Make the requestconstresponse=awaitchatClient.getSpaceEvent(request);// Handle the responseconsole.log(response);}main().catch(console.error);
Per eseguire questo esempio, sostituisci quanto segue:
SCOPE_NAME: un ambito di autorizzazione basato sul
tipo di evento. Ad esempio, se ricevi un evento dello spazio
relativo a un nuovo abbonamento, utilizza l'ambito chat.memberships.readonly,
nel formato https://www.googleapis.com/auth/chat.memberships.readonly.
Puoi ottenere il tipo di evento dal metodo
ListSpaceEvents(). Per scoprire come utilizzare questo metodo, consulta
Elencare gli eventi di uno spazio.
SPACE_NAME: l'ID di name dello spazio.
Puoi ottenere l'ID chiamando il metodo
ListSpaces() o dall'URL dello spazio.
[null,null,["Ultimo aggiornamento 2025-08-29 UTC."],[[["\u003cp\u003eThis guide explains how to retrieve details about specific events within a Google Chat space using the \u003ccode\u003eget()\u003c/code\u003e method of the Google Chat API.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eSpaceEvent\u003c/code\u003e resource tracks changes in a space, and this guide details how to access information about these events.\u003c/p\u003e\n"],["\u003cp\u003eTo use this functionality, you need a Google Workspace account, appropriate authorization, and a configured Google Cloud project.\u003c/p\u003e\n"],["\u003cp\u003eYou must provide the correct authorization scope, space name, and space event name to successfully retrieve the event details.\u003c/p\u003e\n"],["\u003cp\u003eThe API returns a \u003ccode\u003eSpaceEvent\u003c/code\u003e object containing comprehensive information about the requested event.\u003c/p\u003e\n"]]],["The guide details how to retrieve space event information using the `get()` method on the Google Chat API's `SpaceEvent` resource. This method requires user authentication, and the user must be a space member. To use `get()`, provide an authorization scope and the event's name within a request. The API returns the latest `SpaceEvent` data, up to 28 days old, reflecting any changes to the space or its resources. It requires Node.js, a Google Workspace account, and proper API configuration.\n"],null,["# Get details about a Google Chat space event\n\nThis guide explains how to use the\n[`get()`](/workspace/chat/api/reference/rpc/google.chat.v1#google.chat.v1.ChatService.GetSpaceEvent)\nmethod on the `SpaceEvent` resource of the Google Chat API to get details about\nan event from a Google Chat space.\n\nThe\n[`SpaceEvent` resource](/workspace/chat/api/reference/rpc/google.chat.v1#google.chat.v1.SpaceEvent)\nrepresents a change to a space or its child resources, such as messages,\nreactions, and memberships. To learn about the 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)\nreference documentation.\n\nYou can request events up to 28 days before the time of the request. The event\ncontains the most recent version of the resource that changed. For example, if\nyou request an event about a new message but the message was later updated, the\nserver returns the updated `Message` resource in the event payload.\n\nTo call this method, you must use\n[user authentication](/workspace/chat/authenticate-authorize-chat-user). To get\nan event, the authenticated user must be a member of the space where the event\noccurred.\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\nGet details about a space event\n-------------------------------\n\nTo get details about a space event in Google Chat, pass the following in your\nrequest:\n\n- Specify an authorization scope that supports the event type in your request. As a best practice, choose the most restrictive scope that still allows your app to function.\n- Call the [`GetSpaceEvent()`](/workspace/chat/api/reference/rpc/google.chat.v1#google.chat.v1.ChatService.GetSpaceEvent) method, passing the `name` of the space event to get.\n\nThe following example gets a space event: \n\n### Node.js\n\nchat/client-libraries/cloud/get-space-event-user-cred.js \n[View on GitHub](https://github.com/googleworkspace/node-samples/blob/main/chat/client-libraries/cloud/get-space-event-user-cred.js) \n\n```javascript\nimport {createClientWithUserCredentials} from './authentication-utils.js';\n\n// Replace SCOPE_NAME here with an authorization scope based on the event type\nconst USER_AUTH_OAUTH_SCOPES = ['SCOPE_NAME'];\n\n// This sample shows how to get space event 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 and SPACE_EVENT_NAME here\n name: 'spaces/SPACE_NAME/spaceEvents/SPACE_EVENT_NAME'\n };\n\n // Make the request\n const response = await chatClient.getSpaceEvent(request);\n\n // Handle the response\n console.log(response);\n}\n\nmain().catch(console.error);\n```\n\nTo run this sample, replace the following:\n\n- \u003cvar translate=\"no\"\u003eSCOPE_NAME\u003c/var\u003e: an authorization scope based on the event type. For example, if you are getting a space event about a new membership, use the `chat.memberships.readonly` scope, formatted as `https://www.googleapis.com/auth/chat.memberships.readonly`. You can obtain the event type from the [`ListSpaceEvents()`](/workspace/chat/api/reference/rpc/google.chat.v1#google.chat.v1.ChatService.ListSpaceEvents) method. To learn how to use this method, see [List events from a space](/workspace/chat/list-space-events).\n- \u003cvar translate=\"no\"\u003eSPACE_NAME\u003c/var\u003e: the ID from the space's [`name`](/workspace/chat/api/reference/rpc/google.chat.v1#google.chat.v1.Space.FIELDS.string.google.chat.v1.Space.name). You can obtain the ID by calling the [`ListSpaces()`](/workspace/chat/api/reference/rpc/google.chat.v1#google.chat.v1.ChatService.ListSpaces) method or from the space's URL.\n- \u003cvar translate=\"no\"\u003eSPACE_EVENT_NAME\u003c/var\u003e: the ID from the space event's [`name`](/workspace/chat/api/reference/rpc/google.chat.v1#google.chat.v1.SpaceEvent.FIELDS.string.google.chat.v1.SpaceEvent.name). You can obtain the ID from the [`ListSpaceEvents()`](/workspace/chat/api/reference/rpc/google.chat.v1#google.chat.v1.ChatService.ListSpaceEvents) method. To learn how to use this method, see [List events from a space](/workspace/chat/list-space-events).\n\nThe Chat API returns an instance of\n[`SpaceEvent`](/workspace/chat/api/reference/rpc/google.chat.v1#google.chat.v1.SpaceEvent)\nwith details about the event.\n\nRelated topics\n--------------\n\n- [Work with events from Google Chat](/workspace/chat/events-overview)\n- [List events from a Google Chat space](/workspace/chat/list-space-events)"]]