接入教程
1. 访问Wizard World API官网查看接口文档
2. 选择所需端点(如/characters获取角色信息)
3. 发送HTTP请求获取JSON格式数据
4. 解析返回数据并在应用中使用
5. 可结合官方示例代码快速集成
Python获取角色信息示例
import requests
url = 'https://wizard-world-api.herokuapp.com/characters'
headers = {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
}
response = requests.get(url, headers=headers)
if response.status_code == 200:
characters = response.json()
print(f'Found {len(characters)} characters')
for character in characters[:5]:
print(f"Name: {character.get('name')}, House: {character.get('house')}")
else:
print(f'Error: {response.status_code}')
print(response.text)
PHP获取魔杖信息示例
<?php
$url = 'https://wizard-world-api.herokuapp.com/wands';
$options = [
'http' => [
'method' => 'GET',
'header' => "Authorization: Bearer YOUR_API_KEY\r\n" .
"Content-Type: application/json\r\n"
]
];
$context = stream_context_create($options);
$response = file_get_contents($url, false, $context);
if ($response !== false) {
$wands = json_decode($response, true);
echo 'Found ' . count($wands) . ' wands\n';
foreach (array_slice($wands, 0, 5) as $wand) {
echo 'Wand: ' . ($wand['wood'] ?? 'Unknown') .
', Core: ' . ($wand['core'] ?? 'Unknown') . '\n';
}
} else {
echo 'Failed to fetch data';
}
?>
JavaScript获取药水信息示例
const url = 'https://wizard-world-api.herokuapp.com/potions';
const options = {
method: 'GET',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
}
};
fetch(url, options)
.then(response => {
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return response.json();
})
.then(potions => {
console.log(`Found ${potions.length} potions`);
potions.slice(0, 5).forEach(potion => {
console.log(`Potion: ${potion.name || 'Unknown'}, Effect: ${potion.effect || 'Unknown'}`);
});
})
.catch(error => {
console.error('Error fetching potions:', error);
});
常见问题
如何获取API密钥?
请访问Wizard World API官方网站(https://wizard-world-api.herokuapp.com/swagger/index.html)查看注册和获取API密钥的具体流程。目前该API提供免费访问,无需付费订阅。
API是否有调用频率限制?
是的,为了保护服务器资源,Wizard World API实施了调用频率限制。具体限制请参考官方文档,建议在代码中添加适当的延迟以避免超出限制。
API支持哪些数据格式?
Wizard World API主要支持JSON格式的数据交换。所有请求和响应默认使用application/json内容类型。如需其他格式,请查阅官方文档确认是否支持。
Aitishiku.com