接入教程
1. 访问GitHub仓库查看可用日历列表
2. 复制所需地区的ICS文件URL
3. 在日历应用中添加URL订阅
4. 或直接下载ICS文件到本地使用
5. 根据需求定期更新订阅链接
使用Python获取节假日日历
import requests
url = 'https://api.example.com/v1/calendars/region/cn'
headers = {'Authorization': 'Bearer YOUR_API_KEY'}
params = {'year': 2024, 'format': 'ics'}
response = requests.get(url, headers=headers, params=params)
if response.status_code == 200:
calendar_data = response.text
print('Calendar retrieved successfully')
else:
print(f'Error: {response.status_code}')
print(response.text)
使用PHP订阅节假日日历
<?php
$apiUrl = 'https://api.example.com/v1/subscriptions';
$apiKey = 'YOUR_API_KEY';
$data = [
'region' => 'us',
'callback_url' => 'https://your-domain.com/webhook'
];
$ch = curl_init($apiUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer ' . $apiKey,
'Content-Type: application/json'
]);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($httpCode === 201) {
echo 'Subscription created successfully';
} else {
echo 'Error: ' . $httpCode;
echo $response;
}
?>
使用JavaScript获取日历数据
const apiUrl = 'https://api.example.com/v1/calendars';
const apiKey = 'YOUR_API_KEY';
async function fetchCalendar(regionCode) {
try {
const response = await fetch(`${apiUrl}/region/${regionCode}?format=json`, {
headers: {
'Authorization': `Bearer ${apiKey}`,
'Content-Type': 'application/json'
}
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const data = await response.json();
console.log('Calendar data:', data);
return data;
} catch (error) {
console.error('Error fetching calendar:', error);
}
}
// 示例用法
fetchCalendar('jp');
常见问题
如何获取特定地区的节假日日历?
通过向 /v1/calendars/region/{region_code} 端点发送GET请求,其中region_code为地区代码(如cn、us、jp)。您可以选择返回格式(ics或json),并指定年份参数。
API是否支持日历订阅功能?
是的,API提供订阅功能。您可以创建订阅以自动接收特定地区的日历更新。当节假日信息变更时,系统将通过您提供的回调URL发送通知。
请求频率是否有限制?
是的,免费API有请求频率限制。具体限制取决于您的API密钥类型。建议合理缓存日历数据,避免频繁请求相同信息。详细限制请查阅API文档。
Aitishiku.com