接入教程
GET https://api.thecatapi.com/v1/images/search?api_key=你的KEY1. 在 thecatapi.com 注册并获取免费API Key。
2. 请求随机猫咪图片:
3. 按品种筛选:/v1/images/search?breed_ids=beng。
4. 获取品种列表:/v1/breeds。
5. 免费计划每月10000次请求,超出需升级。
Python 获取随机猫咪图片
python
import requests
url = "https://api.thecatapi.com/v1/images/search"
r = requests.get(url, headers={"x-api-key":"你的KEY"})
img = r.json()[0]
print(img["url"])
PHP 获取随机猫咪图片
php
<?php
$ctx = stream_context_create(["http"=>["header"=>"x-api-key: 你的KEY"]]);
$res = file_get_contents("https://api.thecatapi.com/v1/images/search", false, $ctx);
echo json_decode($res,true)[0]["url"];
JavaScript 获取随机猫咪图片
javascript
const res = await fetch("https://api.thecatapi.com/v1/images/search", {headers: {"x-api-key": "你的KEY"}});
const [img] = await res.json();
console.log(img.url);
常见问题
免费额度是多少?
免费计划每月10000次请求,图片可用于学习与非商业用途,商业授权也包含在免费计划中。
需要绑定信用卡吗?
不需要。免费注册即可获取API Key,无需信用卡。
Aitishiku.com