接入教程
1. 选择图片类型:shibes(柴犬)、cats(猫咪)或birds(小鸟)
2. 构造请求URL:https://shibe.online/api/[类型]?count=[数量]
3. 发送GET请求获取图片链接数组
4. 在应用中展示返回的图片URL
5. 可选参数:count控制返回数量(默认1)
6. 直接使用返回的图片URL嵌入网页
使用 Python 获取随机柴犬图片
python
import requests
url = 'http://shibe.online/api/shibes'
params = {
'count': 1,
'urls': True,
'httpsUrls': True
}
response = requests.get(url, params=params)
if response.status_code == 200:
data = response.json()
print('Random Shiba Image URL:', data[0])
else:
print('Request failed:', response.status_code)
使用 PHP 获取随机猫咪图片
php
<?php
$url = 'http://shibe.online/api/cats';
$params = array(
'count' => 2,
'urls' => true
);
$query = http_build_query($params);
$full_url = $url . '?' . $query;
$response = file_get_contents($full_url);
if ($response !== false) {
$data = json_decode($response);
echo 'Cat Image URLs: ' . print_r($data, true);
} else {
echo 'Request failed';
}
?>
使用 JavaScript 获取随机小鸟图片
javascript
fetch('http://shibe.online/api/birds?count=1&urls=true')
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json();
})
.then(data => {
console.log('Random Bird Image URL:', data[0]);
})
.catch(error => {
console.error('Fetch error:', error);
});
常见问题
这个API需要认证或API密钥吗?
不需要。Shibe.Online API 完全免费且无需任何认证或API密钥,可以直接调用。
API返回的图片链接是永久的吗?
API返回的图片URL是直接指向托管图片的地址,通常是稳定可访问的。但建议在应用中适当缓存图片,以确保最佳性能和可靠性。
我可以请求多少张图片?有速率限制吗?
API支持通过 'count' 参数指定请求的图片数量(通常有合理上限,如10张)。虽然目前没有严格的速率限制,但请合理使用,避免过度频繁的请求。
Aitishiku.com