动物宠物知识事实随机内容 娱乐

狗事实API

提供随机狗事实的简单REST API,可用于娱乐或教育目的

查看官方文档 ↗

接入教程

访问 https://kinduff.github.io/dog-api/ 查看文档,使用GET请求访问端点获取随机狗事实

使用requests库获取狗事实

python
import requests

url = 'https://dog-api.kinduff.com/api/facts'
params = {'number': 3}

response = requests.get(url, params=params)
if response.status_code == &200:
    data = response.json()
    facts = data.get('facts', [])
    for fact in facts:
        print(fact)
else:
    print(f'Error: {response.status_code}')

使用cURL调用狗事实API

php
<?php
$url = 'https://dog-api.kinduff.com/api/facts?number=2';

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Accept: application/json'
]);

$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

if ($httpCode == 200) {
    $data = json_decode($response, true);
    $facts = $data['facts'] ?? [];
    foreach ($facts as $fact) {
        echo $fact . "\n";
    }
} else {
    echo "Error: " . $httpCode;
}
?>

使用fetch API获取随机狗事实

javascript
const url = 'https://dog-api.kinduff.com/api/facts';
const params = new URLSearchParams({ number: 1 });

fetch(`${url}?${params}`)
  .then(response => {
    if (!response.ok) throw new Error(`HTTP error: ${response.status}`);
    return response.json();
  })
  .then(data => {
    const facts = data.facts || [];
    facts.forEach(fact => console.log(fact));
  })
  .catch(error => console.error('Error:', error));

常见问题

这个API需要认证或API密钥吗?

不需要,Dog Facts API是完全免费的开放API,无需认证或API密钥即可使用。

API请求频率有限制吗?

该API对合理使用没有严格的速率限制,但建议避免过度频繁的请求以保持服务稳定。

可以一次获取多个狗事实吗?

可以,通过'number'查询参数可以指定获取的事实数量,例如?number=5将返回5个随机狗事实。

相似接口推荐

AWS Compute Optimizer

Compute Optimizer是一项分析亚马逊云服务计算资源配置和利用率的服务,涵盖Amazon EC2实例、Auto Scaling组、Lambda函数、EBS卷及Fargate上的ECS服务。它会评估资源使用效率

待确认
转账API

该API提供端点,用于查询所有交易信息、在余额平台内转移资金,或将资金从余额平台发送至转账工具。

待确认
资金API

该API用于经典集成方案,提供管理平台账户资金的端点功能,包括资金分配、余额查询等操作。如需全新集成请参考官方最新指南。

待确认
Square支付

Square提供便捷的在线收款解决方案,支持支付处理和退款管理,帮助商家优化客户结账体验。

免费试用