接入教程
1. 访问Thirukkural API官网获取API密钥
2. 使用GET请求调用/kural/{编号}端点获取单首诗歌
3. 通过/random端点随机获取诗歌内容
4. 可选参数language设置返回语言(ta/en)
5. 响应包含诗歌原文、翻译和注释字段
6. 集成到您的应用程序展示经典文学作品
Python获取随机蒂鲁古拉尔诗歌
python
import requests
url = 'https://api-thirukkural.web.app/api/v1/kural/random'
headers = {'Authorization': 'Bearer YOUR_API_KEY'}
response = requests.get(url, headers=headers)
if response.status_code == 200:
data = response.json()
print(f"Kural {data['number']}: {data['tamil']}")
print(f"Translation: {data['english']}")
else:
print(f"Error: {response.status_code}")
PHP按编号查询特定诗歌
php
<?php
$apiKey = 'YOUR_API_KEY';
$kuralNumber = 25;
$url = "https://api-thirukkural.web.app/api/v1/kural/{$kuralNumber}";
$options = [
'http' => [
'header' => "Authorization: Bearer {$apiKey}\r\n"
]
];
$context = stream_context_create($options);
$response = file_get_contents($url, false, $context);
if ($response !== false) {
$data = json_decode($response, true);
echo "Kural {$data['number']}: {$data['tamil']}\n";
echo "Explanation: {$data['explanation']}\n";
} else {
echo "Failed to fetch data\n";
}
?>
JavaScript获取诗歌列表
javascript
const apiKey = 'YOUR_API_KEY';
const url = 'https://api-thirukkural.web.app/api/v1/kural/list?limit=10';
fetch(url, {
headers: {
'Authorization': `Bearer ${apiKey}`
}
})
.then(response => response.json())
.then(data => {
data.kurals.forEach(kural => {
console.log(`#${kural.number}: ${kural.tamil.substring(0, 50)}...`);
});
})
.catch(error => console.error('Error:', error));
常见问题
如何获取API访问权限?
请访问官方网站注册账户并申请API密钥。免费套餐提供基础访问权限,高级功能需订阅相应计划。
API支持哪些查询参数?
支持按编号查询特定诗歌、随机获取、分页列表、语言筛选(泰米尔语/英语)等参数。具体参数请参考官方文档。
API请求频率是否有限制?
免费套餐每分钟限制60次请求,每日限制5000次。如需更高限制,请升级到付费套餐。所有请求需包含有效的API密钥。
Aitishiku.com