Logo
Section 1 / 3

搜索动图和贴纸

学习如何使用 GIPHY API 的搜索端点。

导入

搜索动图和贴纸

学习如何使用 GIPHY API 的搜索端点。

...
...
搜索端点

代码示例

1https://api.giphy.com/v1/gifs/search?api_key={ourGIPHYapikey}&q={queryString}
参数名类型分类描述
q字符串必填搜索查询词或短语。q 的最大长度为 50 个字符。
limit整数 (int32)可选用于指定返回的最大 GIF 数量。默认返回 50 个 GIF,若将 limit 设置为 10,则仅返回 10 个 GIF。
offset整数 (int32)可选用于指定结果的起始位置。默认从 "0" 开始获取 GIF。若设置 offset 为 5,则返回结果从第 5 个 GIF 开始(即数据库中的第五个 GIF 成为结果中的第一个)。offset 最大值为 4999。
rating字符串可选用于按指定评级过滤结果。可接受的值包括 g、pg、pg-13 和 r。若未指定评级,则返回所有可能评级的结果。
lang字符串可选用于指定区域内容的默认语言。有效值为两个字母的 ISO 639-1 语言代码。
bundle字符串可选用于获取对应命名包的渲染版本。例如,将 bundle 设置为 messaging_non_clips,仅返回适合用于消息传递的 GIF。
1const fetch = require('node-fetch'); 2 3let url = new URL('https://api.giphy.com/v1/gifs/search'); 4url.search = new URLSearchParams({ 5 api_key: '{{API_KEY}}', 6 q: '{{QUERY}}' 7}); 8 9fetch(url) 10 .then(response => response.json()) 11 .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 上被标记为热门的时间和日期。仅在适用时存在。
images对象包含各种可用 GIF 尺寸和格式的数据。
user对象包含与 GIF 关联的用户信息(如果适用)。通常为创建或上传 GIF 到 giphy.com 的人。
analytics对象包含记录用户行为的数据,如查看、点击或发送 GIF 的时间。

代码示例

1https://api.giphy.com/v1/stickers/search?api_key={ourGIPHYapikey}&q={queryString}
1const fetch = require('node-fetch'); 2 3let url = new URL('https://api.giphy.com/v1/stickers/search'); 4url.search = new URLSearchParams({ 5 api_key: '{{API_KEY}}', 6 q: '{{QUERY}}' 7}); 8 9fetch(url) 10 .then(response => response.json()) 11 .then(data => console.log(JSON.stringify(data, null, 4)));
1const fetch = require('node-fetch'); 2 3let url = new URL('https://api.giphy.com/v1/gifs/search'); 4url.search = new URLSearchParams({ 5 api_key: '{{API_KEY}}', 6 q: '{{QUERY}}', 7 limit: 6 8}); 9 10// 调用渲染 GIF 的函数 11render();
1const fetch = require('node-fetch'); 2 3let url = new URL('https://api.giphy.com/v1/stickers/search'); 4url.search = new URLSearchParams({ 5 api_key: '{{API_KEY}}', 6 q: '{{QUERY}}', 7 limit: 6, 8 offset: 50 9}); 10 11// 调用渲染贴纸的函数 12render();

GIF 动图和表情贴纸

搜索辅助工具