接入教程
1. 访问Shikimori官网注册获取API密钥
2. 查看API文档了解可用端点
3. 使用GET请求获取动漫信息
4. 通过OAuth进行用户认证
5. 实现进度追踪和评分功能
6. 集成到您的应用中
获取动漫信息
python
import requests
base_url = 'https://shikimori.one/api'
headers = {
'User-Agent': 'YourAppName/1.0',
'Authorization': 'Bearer YOUR_API_KEY'
}
# 搜索动漫
response = requests.get(f'{base_url}/animes',
headers=headers,
params={'search': 'Attack on Titan'})
if response.status_code == 200:
animes = response.json()
print(f'Found {len(animes)} anime(s)')
else:
print(f'Error: {response.status_code}')
# 获取特定动漫详情
anime_id = 16498 # 示例ID
response = requests.get(f'{base_url}/animes/{anime_id}',
headers=headers)
if response.status_code == 200:
anime_details = response.json()
print(f"Title: {anime_details.get('name')}")
print(f"Score: {anime_details.get('score')}")
else:
print(f'Error: {response.status_code}')
用户观看进度管理
php
<?php
$base_url = 'https://shikimori.one/api';
$api_key = 'YOUR_API_KEY';
// 设置请求头
$headers = [
'User-Agent: YourAppName/1.0',
'Authorization: Bearer ' . $api_key
];
// 获取用户观看列表
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $base_url . '/user_rates');
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($http_code == 200) {
$user_rates = json_decode($response, true);
echo 'User has ' . count($user_rates) . ' anime in list';
} else {
echo 'Error: ' . $http_code;
}
// 添加新的观看进度
$data = [
'user_id' => 12345, // 示例用户ID
'target_id' => 16498, // 动漫ID
'target_type' => 'Anime',
'score' => miniature,
'status' => 'watching'
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $base_url . '/user_rates');
curl_setopt($ch, CURLOPT_HTTPHEADER, array_merge($headers, ['Content-Type: application/json']));
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($http_code == 201) {
echo 'Progress added successfully';
} else {
echo 'Error: ' . $http_code;
}
?>
论坛帖子获取与搜索
javascript
const baseUrl = 'https://shikimori.one/api';
const apiKey = 'YOUR_API_KEY';
async function fetchForumTopics() {
const headers = {
'User-Agent': 'YourAppName/1.0',
'Authorization': `Bearer ${apiKey}`
};
try {
// 获取论坛话题
const response = await fetch(`${baseUrl}/topics`, {
method: 'GET',
headers: headers
});
if (response.ok) {
const topics = await response.json();
console.log(`Found ${topics.length} forum topics`);
return topics;
} else {
console.error(`Error: ${response.status}`);
return null;
}
} catch (error) {
console.error('Network error:', error);
return null;
}
}
async function searchForumPosts(query) {
const headers = {
'User-Agent': 'YourAppName/1.0',
'Authorization': `Bearer ${apiKey}`
};
try {
const response = await fetch(
`${baseUrl}/topics?forum=all&search=${encodeURIComponent(query)}`,
{
method: 'GET',
headers: headers
}
);
if (response.ok) {
const results = await response.json();
console.log(`Found ${results.length} posts for query: ${query}`);
return results;
} else {
console.error(`Error: ${response.status}`);
return null;
}
} catch (error) {
console.error('Network error:', error);
return null;
}
}
// 使用示例
fetchForumTopics();
searchForumPosts('new anime releases');
常见问题
如何获取Shikimori API的访问权限?
首先需要在Shikimori网站上注册账号,然后在个人设置中创建应用程序以获取API密钥。部分接口可能需要额外权限申请。
API请求频率是否有限制?
Shikimori API有请求频率限制,通常为每分钟60次请求。建议在客户端实现适当的请求间隔和缓存机制以避免超限。
API支持哪些数据格式?
Shikimori API主要支持JSON格式的数据交换。所有请求和响应都使用JSON,确保设置正确的Content-Type请求头。
Aitishiku.com