接入教程
1. 访问GitHub仓库查看文档
2. 使用API端点获取经文数据
3. 根据需求选择语言或翻译版本
4. 在项目中调用API接口
5. 处理返回的JSON数据
使用Python获取古兰经章节列表
python
import requests
url = 'https://api.example.com/chapters'
headers = {'Authorization': 'Bearer YOUR_API_KEY'}
response = requests.get(url, headers=headers)
if response.status_code == 200:
chapters = response.json()
print(f'Found {len(chapters)} chapters')
else:
print(f'Error: {response.status_code}')
print(response.text)
使用PHP获取特定章节的经文
php
<?php
$apiKey = 'YOUR_API_KEY';
$chapterId = 1;
$url = 'https://api.example.com/chapters/' . $chapterId . '/verses';
$options = [
'http' => [
'header' => "Authorization: Bearer $apiKey\r\n",
'method' => 'GET'
]
];
$context = stream_context_create($options);
$response = file_get_contents($url, false, $context);
if ($response !== false) {
$verses = json_decode($response, true);
echo 'Verses retrieved: ' . count($verses);
} else {
echo 'Failed to fetch verses.';
}
?>
使用JavaScript搜索经文内容
javascript
const apiKey = 'YOUR_API_KEY';
const query = 'mercy';
const url = `https://api.example.com/search?query=${encodeURIComponent(query)}`;
fetch(url, {
method: 'GET',
headers: {
'Authorization': `Bearer ${apiKey}`,
'Content-Type': 'application/json'
}
})
.then(response => {
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return response.json();
})
.then(data => {
console.log(`Search results for "${query}":`, data.results);
})
.catch(error => {
console.error('Fetch error:', error);
});
常见问题
如何获取API密钥?
该API服务完全免费且无需API密钥即可使用。只需在请求中使用基础URL即可访问公开数据。如需高级功能或更高调用限制,请查阅官方文档。
支持哪些语言的翻译?
该API支持90多种语言和400多种翻译版本,包括阿拉伯语、英语、中文、法语、乌尔都语等主要语言。可通过指定语言代码参数来获取特定翻译。
是否有调用频率限制?
是的,为了保护服务稳定性,API设有合理的调用频率限制。具体限制数值请参考官方文档。建议在客户端实现适当的请求缓存和错误重试机制。
Aitishiku.com