This guide explains how to use the
get()
method on the SpaceEvent
resource of the Google Chat API to get details about
an event from a Google Chat space.
The
SpaceEvent
resource
represents a change to a space or its child resources, such as messages,
reactions, and memberships. To learn about the supported event types, see the
eventType
field of the SpaceEvent
resource
reference documentation.
You can request events up to 28 days before the time of the request. The event
contains the most recent version of the resource that changed. For example, if
you request an event about a new message but the message was later updated, the
server returns the updated Message
resource in the event payload.
To call this method, you must use user authentication. To get an event, the authenticated user must be a member of the space where the event occurred.
Prerequisites
Node.js
- A Business or Enterprise Google Workspace account with access to Google Chat.
- Set up your environment:
- Create a Google Cloud project.
- Configure the OAuth consent screen.
- Enable and configure the Google Chat API with a name, icon, and description for your Chat app.
- Install the Node.js Cloud Client Library.
-
Create OAuth client ID credentials for a desktop application. To run the sample in this
guide, save the credentials as a JSON file named
client_secrets.json
to your local directory.
- Choose an authorization scope that supports user authentication.
Get details about a space event
To get details about a space event in Google Chat, pass the following in your request:
- 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.
- Call the
GetSpaceEvent()
method, passing thename
of the space event to get.
The following example gets a space event:
Node.js
To run this sample, replace the following:
SCOPE_NAME
: an authorization scope based on the event type. For example, if you are getting a space event about a new membership, use thechat.memberships.readonly
scope, formatted ashttps://www.googleapis.com/auth/chat.memberships.readonly
. You can obtain the event type from theListSpaceEvents()
method. To learn how to use this method, see List events from a space.SPACE_NAME
: the ID from the space'sname
. You can obtain the ID by calling theListSpaces()
method or from the space's URL.SPACE_EVENT_NAME
: the ID from the space event'sname
. You can obtain the ID from theListSpaceEvents()
method. To learn how to use this method, see List events from a space.
The Chat API returns an instance of
SpaceEvent
with details about the event.