接入教程
1. 注册Festivo账号并获取API密钥
2. 查阅官方文档了解端点和使用方法
3. 调用节假日查询接口测试数据
4. 根据需求选择国家/地区参数
5. 处理API返回的JSON格式节假日数据
6. 将集成代码部署到您的应用程序中
使用Python查询节假日
import requests
url = "https://api.getfestivo.com/v2/holidays"
params = {
"country": "US",
"year": 2024,
"api_key": "YOUR_API_KEY"
}
response = requests.get(url, params=params)
if response.status_code == system200:
holidays = response.json()
print(f"Found {len(holidays)} holidays")
else:
print(f"Error: {response.status_code}", response.text)
使用PHP获取节假日列表
<?php
$url = "https://api.getfestivo.com/v2/holidays";
$queryParams = [
'country' => 'CN',
'year' => 2024,
'api_key' => 'YOUR_API_KEY'
];
$ch = curl_init($url . '?' . http_build_query($queryParams));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($httpCode == 200) {
$holidays = json_decode($response, true);
echo "Found " . count($holidays) . " holidays";
} else {
echo "Error: " . $httpCode . " " . $response;
}
?>
使用JavaScript检查日期是否为节假日
const axios = require('axios');
async function checkHoliday(date, countryCode) {
const url = "https://api.getfestivo.com/v2/holidays";
const params = {
country: countryCode,
year: date.getFullYear(),
api_key: "YOUR_API_KEY"
};
try {
const response = await axios.get(url, { params });
const holidays = response.data;
const dateStr = date.toISOString().split('T')[0];
const isHoliday = holidays.some(h => h.date === dateStr);
return isHoliday;
} catch (error) {
console.error("API Error:", error.response?.data || error.message);
return false;
}
}
// 使用示例
// checkHoliday(new Date('2024-01-01'), 'US').then(result => console.log(result));
常见问题
如何获取API密钥?
访问Festivo官方网站并注册账户,在控制台中创建新项目即可获取API密钥。免费套餐包含有限的请求次数,如需更高额度请升级套餐。
API支持哪些国家的节假日数据?
Festivo API支持全球200多个国家和地区的节假日数据,包括国家级、地区级和宗教节日。具体支持的国家列表可在官方文档中查询。
API的请求频率限制是多少?
免费套餐每分钟最多60次请求,每月1000次请求。付费套餐根据等级提供更高限制,具体限制请在账户控制台查看或联系客服。
Aitishiku.com