8 个版本 (4 个破坏性更改)
0.5.1 | 2022 年 4 月 12 日 |
---|---|
0.5.0 | 2021 年 9 月 4 日 |
0.4.0 | 2021 年 8 月 8 日 |
0.3.2 | 2021 年 8 月 4 日 |
0.1.0 | 2021 年 7 月 27 日 |
#5 in #mal
56KB
1K SLoC
lib-mal
与 MyAnimeList API 交互的库
处理授权,只需要 MyAnimeList API 的客户端 ID 和已注册的重定向 URI,用户可以使用由 MALClient
生成的 URL 授权应用程序。默认情况下,令牌会被缓存,但创建客户端时可以禁用此功能。
API 函数仍在开发中
目前不支持漫画列表功能,但将来可能会实现
入门指南
要使用 lib-mal
,您需要从 MyAnimeList.net 获取 API 密钥和一个回调 URL。以下是一个使用 lib-mal
的示例:
use lib_mal::{MALClient, MALError};
use tokio;
#[tokio::main]
async fn main() -> Result<(), MALError>{
//this has to exactly match a URI that's been registered with the MAL api
let redirect = [YOUR_REDIRECT_URI_HERE];
//the MALClient will attempt to refresh the cached access_token, if applicable
let client = MALClient::init([YOUR_SECRET_HERE]).await;
let (auth_url, challenge, state) = client.get_auth_parts();
//the user will have to have access to a browser in order to log in and give your application permission
println!("Go here to log in :) -> {}", auth_url);
//once the user has the URL, be sure to call client.auth to listen for the callback and complete the OAuth2 handshake
client.auth(&redirect, &challenge, &state).await.expect("Unable to log in");
//once the user is authorized, the API should be usable
//this will get the details, including all fields, for Mobile Suit Gundam
let anime = client.get_anime_details(80, None).await?;
//because so many fields are optional, a lot of the members of lib_mal::model::AnimeDetails are `Option`s
println!("{}: started airing on {}, ended on {}, ranked #{}", anime.show.title, anime.start_date.unwrap(), anime.end_date.unwrap(), anime.rank.unwrap());
}
依赖项
~8–20MB
~327K SLoC