Logo
Section 1 / 5

热门GIF和表情贴纸

学习如何获取 GIPHY 的热门 GIF 和贴纸。

导入

热门GIF和表情贴纸

学习如何获取 GIPHY 的热门 GIF 和贴纸。

GIPHY 提供了趋势接口,用于获取其数据库中当前正在 trending 的所有内容。他们持续更新趋势内容的推送,使我们能够随时获取最新、最相关且最具吸引力的内容。

Course Image
...
GIF 趋势接口

代码示例

1https://api.giphy.com/v1/gifs/trending?api_key={ourGIPHYapikey}
参数名类型可选性描述
limit整数 (int32)可选用于指定返回的最大 GIF 数量。默认返回 50 个 GIF,若将 limit 设置为 10,则仅返回 10 个 GIF。
offset整数 (int32)可选用于指定结果的起始位置。默认从 "0" 开始获取 GIF。若设置 offset 为 5,则返回的 GIF 将从第 5 个开始(即数据库中的第五个 GIF 成为结果中的第一个)。offset 最大值为 4999。
rating字符串可选用于按指定评级过滤结果。可接受的值包括 g、pg、pg-13 和 r。若不指定评级,则返回所有可能评级的结果。
bundle字符串可选用于获取对应命名包的渲染版本。例如,若设置 bundle 为 messaging_non_clips,将仅返回适合用于消息传递的 GIF。
1const fetch = require('node-fetch'); 2 3let url = new URL('https://api.giphy.com/v1/gifs/trending'); 4url.search = new URLSearchParams({ 5 api_key: '{{API_KEY}}' 6}); 7 8fetch(url) 9 .then(response => response.json()) 10 .then(data => console.log(JSON.stringify(data, null, 4)));
...
趋势接口输出组件

字段名类型描述
type字符串表示返回的对象是 GIF 还是贴纸。type 的默认值几乎总是 gif。
id字符串GIF 的唯一标识 ID。
url字符串GIF 的唯一 URL 地址。
username字符串该 GIF 所属频道的用户名。仅在适用时存在。
source字符串GIF 所在的网页来源。例如:Reddit、HBO Max、giphy.com 等。
title字符串GIF 在 giphy.com 上显示的标题。
rating字符串GIF 内容的 MPAA(美国电影协会)风格评级。有效值包括 g、pg、pg-13、r。
source_post_url字符串GIF 所在网页的完整 URL。
import_datetime字符串表示 GIF 创建或上传到源平台的时间。例如:2021-08-01 12:41:48。
trending_datetime字符串表示 GIF 在 giphy.com 上被标记为 trending 的时间。仅在适用时存在。
images对象包含不同尺寸和格式的 GIF 数据。
user对象包含与 GIF 关联的用户信息(如果适用)。通常为创建或上传 GIF 到 giphy.com 的人。
analytics对象包含用户行为数据,如查看、点击或发送 GIF 的记录。
...
趋势贴纸接口

代码示例

1https://api.giphy.com/v1/stickers/trending?api_key={ourGIPHYapikey}
1let url = new URL('https://api.giphy.com/v1/stickers/trending');
1const fetch = require('node-fetch'); 2 3let url = new URL('https://api.giphy.com/v1/gifs/trending'); 4url.search = new URLSearchParams({ 5 api_key: '{{API_KEY}}', 6 rating: 'g' 7}); 8 9// 调用渲染 GIF 的函数 10render();
1const fetch = require('node-fetch'); 2 3let url = new URL('https://api.giphy.com/v1/stickers/trending'); 4url.search = new URLSearchParams({ 5 api_key: '{{API_KEY}}', 6 rating: 'g' 7}); 8 9// 调用渲染贴纸的函数 10render();

简介

将文字转换为GIF和表情贴纸