Xem thông tin chi tiết về một biểu tượng cảm xúc tuỳ chỉnh
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Hướng dẫn này giải thích cách sử dụng phương thức get trên tài nguyên CustomEmoji của API Google Chat để biết thông tin chi tiết về một biểu tượng cảm xúc tuỳ chỉnh.
Tạo thông tin đăng nhập để truy cập dựa trên cách bạn muốn xác thực trong yêu cầu Google Chat API:
Để xác thực với tư cách là người dùng Chat, hãy tạo thông tin xác thực mã ứng dụng OAuth và lưu thông tin xác thực dưới dạng tệp JSON có tên credentials.json vào thư mục cục bộ của bạn.
import{createClientWithUserCredentials}from'./authentication-utils.js';constUSER_AUTH_OAUTH_SCOPES=['https://www.googleapis.com/auth/chat.customemojis'];// This sample shows how to get custom emoji with user credentialasyncfunctionmain(){// Create a clientconstchatClient=awaitcreateClientWithUserCredentials(USER_AUTH_OAUTH_SCOPES);// Initialize request argument(s)constrequest={// TODO(developer): Replace EMOJI_NAME herename:'customEmojis/EMOJI_NAME'};// Make the requestconstresponse=awaitchatClient.getCustomEmoji(request);// Handle the responseconsole.log(response);}main().catch(console.error);
Để chạy mẫu này, hãy thay thế các nội dung sau:
EMOJI_NAME: tên duy nhất cho biểu tượng cảm xúc tuỳ chỉnh của bạn, trong trường emoji_name.
Bạn có thể lấy mã nhận dạng bằng cách gọi phương thức ListCustomEmoji() hoặc từ nội dung phản hồi được trả về sau khi tạo biểu tượng cảm xúc tuỳ chỉnh không đồng bộ bằng Chat API.
[null,null,["Cập nhật lần gần đây nhất: 2025-08-29 UTC."],[],[],null,["# Get details about a custom emoji\n\nThis guide explains how to use the\n[`get`](/workspace/chat/api/reference/rpc/google.chat.v1#google.chat.v1.ChatService.GetCustomEmoji)\nmethod on the\n[`CustomEmoji`](/workspace/chat/api/reference/rpc/google.chat.v1#google.chat.v1.CustomEmoji)\nresource of the Google Chat API to get details about a custom emoji.\n\nCustom emojis are only available for Google Workspace accounts, and your\nadministrator must turn custom emoji on for your organization. For more\ninformation, see [Learn about custom emoji in Google Chat](https://support.google.com/chat/answer/12800149) and\n[Manage custom emoji permissions](https://support.google.com/a/answer/12850085).\n\nPrerequisites\n-------------\n\n\n### Node.js\n\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 access credentials based on how you want to authenticate in your Google Chat API request:\n - To authenticate as a Chat user, [create OAuth client ID\n credentials](/workspace/chat/authenticate-authorize-chat-user) and save the credentials as a JSON file named `credentials.json` to your local directory.\n - To authenticate as the Chat app, [create service account\n credentials](/workspace/chat/authenticate-authorize-chat-app) and save the credentials as a JSON file named `credentials.json`.\n- [Choose an authorization scope](/workspace/chat/authenticate-authorize#asynchronous-chat-calls) based on whether you want to authenticate as a user or the Chat app.\n\n\u003cbr /\u003e\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 custom emoji\n--------------------------------\n\nTo get details about a custom emoji with\n[user authentication](/workspace/chat/authenticate-authorize-chat-user), pass\nthe following in your request:\n\n- Specify the `chat.customemojis` authorization scope.\n- Call the [`GetCustomEmoji`](/workspace/chat/api/reference/rpc/google.chat.v1#google.chat.v1.ChatService.GetCustomEmoji) method.\n- In the request body, set `name` to the resource name of the custom emoji to get.\n\nThe following example gets details of a custom emoji. \n\n### Node.js\n\nchat/client-libraries/cloud/get-custom-emoji-user-cred.js \n[View on GitHub](https://github.com/googleworkspace/node-samples/blob/main/chat/client-libraries/cloud/get-custom-emoji-user-cred.js) \n\n```javascript\nimport {createClientWithUserCredentials} from './authentication-utils.js';\n\nconst USER_AUTH_OAUTH_SCOPES = ['https://www.googleapis.com/auth/chat.customemojis'];\n\n// This sample shows how to get custom emoji 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 // TODO(developer): Replace EMOJI_NAME here\n name: 'customEmojis/EMOJI_NAME'\n };\n\n // Make the request\n const response = await chatClient.getCustomEmoji(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\"\u003eEMOJI_NAME\u003c/var\u003e: the unique name for your custom emoji, in the [`emoji_name`](/workspace/chat/api/reference/rpc/google.chat.v1#google.chat.v1.CustomEmoji.FIELDS.string.google.chat.v1.CustomEmoji.emoji_name) field. You can obtain the ID by calling the [`ListCustomEmoji()`](/workspace/chat/api/reference/rpc/google.chat.v1#google.chat.v1.ChatService.ListCustomEmoji) method, or from the response body returned after creating a custom emoji asynchronously with the Chat API.\n\nRelated topics\n--------------\n\n- [Create a custom emoji](/workspace/chat/create-custom-emoji)\n- [Delete a custom emoji](/workspace/chat/delete-custom-emoji)\n- [List custom emojis in an organization](/workspace/chat/list-custom-emojis)"]]