接入教程
GET https://api.giphy.com/v1/gifs/search?api_key=你的KEY&q=cats1. 注册GIPHY开发者账号并创建应用,获得Beta API Key。
2. 搜索GIF:
3. 热门GIF:/v1/gifs/trending。
4. 随机GIF:/v1/gifs/random。
5. Beta Key限速100次/小时,需要更高额度可申请Production Key。
Python 搜索GIF
python
import requests
url = "https://api.giphy.com/v1/gifs/search"
r = requests.get(url, params={"api_key":"你的KEY","q":"cats","limit":5})
for g in r.json()["data"]:
print(g["images"]["downsized"]["url"])
PHP 搜索GIF
php
<?php
$url = "https://api.giphy.com/v1/gifs/search?api_key=你的KEY&q=cats&limit=5";
$d = json_decode(file_get_contents($url), true);
foreach ($d["data"] as $g) { echo $g["images"]["downsized"]["url"] . "\n"; }
JavaScript 搜索GIF
javascript
const url = "https://api.giphy.com/v1/gifs/search?api_key=你的KEY&q=cats&limit=5";
const data = await fetch(url).then(r => r.json());
data.data.forEach(g => console.log(g.images.downsized.url));
常见问题
Beta Key免费吗?
免费,限速每小时100次调用,适合绝大多数个人项目;生产高流量需申请Production Key。
需要绑定信用卡吗?
不需要。注册账号创建应用即可获得Beta密钥。
Aitishiku.com