Оптимизируйте свои подборки
Сохраняйте и классифицируйте контент в соответствии со своими настройками.
В этом руководстве объясняется, как использовать метод list() ресурса Reaction API Google Chat для вывода списка реакций на сообщение, например 👍, 🚲 и 🌞.
Ресурс Reaction представляет собой эмодзи, которые люди могут использовать для реагирования на сообщение, например, 👍, 🚲 и 🌞.
Создайте учётные данные OAuth-клиента для настольного приложения. Чтобы запустить пример из этого руководства, сохраните учётные данные в виде JSON-файла с именем credentials.json в локальном каталоге.
Для получения руководства выполните шаги по настройке вашей среды, описанные в этом кратком руководстве .
import{createClientWithUserCredentials}from'./authentication-utils.js';constUSER_AUTH_OAUTH_SCOPES=['https://www.googleapis.com/auth/chat.messages.reactions.readonly'];// This sample shows how to list reactions to a message with user credentialasyncfunctionmain(){// Create a clientconstchatClient=awaitcreateClientWithUserCredentials(USER_AUTH_OAUTH_SCOPES);// Initialize request argument(s)constrequest={// Replace SPACE_NAME and MESSAGE_NAME here.parent:'spaces/SPACE_NAME/messages/MESSAGE_NAME'};// Make the requestconstpageResult=chatClient.listReactionsAsync(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 пространства.
MESSAGE_NAME : идентификатор из name сообщения. Идентификатор можно получить из тела ответа, возвращаемого после асинхронного создания сообщения с помощью API чата, или с помощью пользовательского имени, назначенного сообщению при создании.
[null,null,["Последнее обновление: 2025-08-04 UTC."],[[["\u003cp\u003eThis guide explains how to use the \u003ccode\u003elist()\u003c/code\u003e method to retrieve reactions (e.g., 👍, 🚲, 🌞) for messages in Google Chat using the Google Chat API.\u003c/p\u003e\n"],["\u003cp\u003eBefore you begin, ensure you have a Google Workspace account, set up a Google Cloud project, enable the Google Chat API, and install the Node.js Cloud Client Library.\u003c/p\u003e\n"],["\u003cp\u003eTo list reactions, call the \u003ccode\u003eListReactions()\u003c/code\u003e method, providing the message's resource name and specifying the necessary authorization scope.\u003c/p\u003e\n"],["\u003cp\u003eYou'll need the space ID and message ID to construct the resource name for the \u003ccode\u003eListReactions()\u003c/code\u003e method call.\u003c/p\u003e\n"],["\u003cp\u003eThe Chat API returns a paginated list of reactions for the specified message.\u003c/p\u003e\n"]]],["This guide details listing reactions (emojis like 👍, 🚲, 🌞) on Google Chat messages using the Chat API's `ListReactions()` method. Key actions include setting up a Google Cloud project, enabling the Chat API, and obtaining OAuth credentials. To list reactions, specify the appropriate authorization scope (`chat.messages.reactions.readonly`, etc.) and call `ListReactions()`, passing the message's resource name as the `parent`. The API returns a paginated list of reactions.\n"],null,["# List reactions for a message\n\nThis guide explains how to use the\n[`list()`](/workspace/chat/api/reference/rpc/google.chat.v1#google.chat.v1.ChatService.ListReactions)\nmethod on the `Reaction` resource of the Google Chat API to list reactions for a\nmessage---like 👍, 🚲, and 🌞.\n\nThe\n[`Reaction` resource](/workspace/chat/api/reference/rest/v1/spaces.messages.reactions)\nrepresents an emoji that people can use to react to a message, such as 👍, 🚲,\nand 🌞.\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 reactions\n--------------\n\nTo list the reactions for a message, pass the following in your request:\n\n- Specify the `chat.messages.reactions.readonly`, `chat.messages.reactions`, `chat.messages.readonly`, or `chat.messages` authorization scope.\n- Call the [`ListReactions()`](/workspace/chat/api/reference/rpc/google.chat.v1#google.chat.v1.ChatService.ListReactions) method, passing the `parent` as the resource name of the message.\n\nThe following example lists reactions for a specified message: \n\n### Node.js\n\nchat/client-libraries/cloud/list-reactions-user-cred.js \n[View on GitHub](https://github.com/googleworkspace/node-samples/blob/main/chat/client-libraries/cloud/list-reactions-user-cred.js) \n\n```javascript\nimport {createClientWithUserCredentials} from './authentication-utils.js';\n\nconst USER_AUTH_OAUTH_SCOPES = ['https://www.googleapis.com/auth/chat.messages.reactions.readonly'];\n\n// This sample shows how to list reactions to a message 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 MESSAGE_NAME here.\n parent: 'spaces/SPACE_NAME/messages/MESSAGE_NAME'\n };\n\n // Make the request\n const pageResult = chatClient.listReactionsAsync(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 the following:\n\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\"\u003eMESSAGE_NAME\u003c/var\u003e: the ID from the message's [`name`](/workspace/chat/api/reference/rpc/google.chat.v1#google.chat.v1.Message.FIELDS.string.google.chat.v1.Message.name). You can obtain the ID from the response body returned after creating a message asynchronously with the Chat API, or with the [custom name](/workspace/chat/create-messages#name_a_created_message) assigned to the message at creation.\n\nThe Chat API returns a\n[paginated list of reactions](/workspace/chat/api/reference/rpc/google.chat.v1#listreactionsresponse).\n\nRelated topics\n--------------\n\n- [Add a reaction to a message](/workspace/chat/create-reactions).\n- [Delete a reaction from a message](/workspace/chat/delete-reactions)."]]