接入教程
要使用AniList API,首先需要注册开发者账号并获取API密钥。然后可以通过GraphQL查询语言访问数据库。
Python示例
python
import requests
query = '''
{
Page {
media(type: ANIME) {
id
title {
english
}
}
}
}
'''
url = 'https://graphql.anilist.co'
response = requests.post(url, json={'query': query})
print(response.json())
PHP示例
php
<?php
$query = '{
Page {
media(type: ANIME) {
id
title {
english
}
}
}
}';
$url = 'https://graphql.anilist.co';
$options = [
'http' => [
'header' => "Content-type: application/json\r\n",
'method' => 'POST',
'content' => json_encode(['query' => $query]),
],
];
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
var_dump(json_decode($result));
JavaScript示例
javascript
const query = `
{
Page {
media(type: ANIME) {
id
title {
english
}
}
}
}
`;
fetch('https://graphql.anilist.co', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
},
body: JSON.stringify({
query: query
})
})
.then(r => r.json())
.then(data => console.log(data));
常见问题
AniList API是免费的吗?
是的,AniList API目前是免费的,但需要注册开发者账号获取API密钥。
AniList API有请求限制吗?
官方文档没有明确说明具体的请求限制,但建议合理使用API以避免被限制。
Aitishiku.com