获取有关自定义表情符号的详细信息

本指南介绍了如何使用 Google Chat API 的 CustomEmoji 资源的 get 方法来获取有关自定义表情符号的详细信息。

自定义表情符号仅适用于 Google Workspace 账号,并且您的管理员必须为贵组织启用自定义表情符号。如需了解详情,请参阅了解 Google Chat 中的自定义表情符号管理自定义表情符号权限

前提条件

Node.js

获取有关自定义表情符号的详细信息

如需获取有关自定义表情符号的详细信息,请在请求中传递以下内容:用户身份验证

  • 指定 chat.customemojis 授权范围。
  • 调用 GetCustomEmoji 方法。
  • 在请求正文中,将 name 设置为要获取的自定义表情符号的资源名称。

以下示例会获取自定义表情符号的详细信息。

Node.js

chat/client-libraries/cloud/get-custom-emoji-user-cred.js
import {createClientWithUserCredentials} from './authentication-utils.js';

const USER_AUTH_OAUTH_SCOPES = ['https://www.googleapis.com/auth/chat.customemojis'];

// This sample shows how to get custom emoji with user credential
async function main() {
  // Create a client
  const chatClient = await createClientWithUserCredentials(USER_AUTH_OAUTH_SCOPES);

  // Initialize request argument(s)
  const request = {
    // TODO(developer): Replace EMOJI_NAME here
    name: 'customEmojis/EMOJI_NAME'
  };

  // Make the request
  const response = await chatClient.getCustomEmoji(request);

  // Handle the response
  console.log(response);
}

main().catch(console.error);

如需运行此示例,请替换以下内容:

  • EMOJI_NAME:自定义表情符号的唯一名称,位于 emoji_name 字段中。您可以通过调用 ListCustomEmoji() 方法获取 ID,也可以通过 Chat API 异步创建自定义表情符号后从返回的响应正文中获取 ID。