pixiv crate provides an unofficial library for the Pixiv API.
This crate uses the crates
To authenticate, you need to create a new
Pixiv struct and pass in a
reqwest::Client, then login with your username and password.
let client = Client::new(); let mut pixiv: Pixiv = Pixiv::new(&client); pixiv.login("username", "password");
If and when your access token does expire, you should use the
Alternatively, if you have your access token and/or request token cached somwhere for you to reuse:
let client = Client::new(); let mut pixiv: Pixiv = Pixiv::new(&client); let my_access_token = String::from("supersecret"); *pixiv.access_token_mut() = my_access_token;
Accessor methods such as
refresh_token() are provided for these purposes.
This crate relies on the builder pattern for using and modifying a request. A typical request may look like this:
let work: Value = pixiv .work(66024340) .send() .expect("Request failed.") .json() .expect("Failed to parse as json.");
A more complicated response may look like this:
let following_works: Value = pixiv .following_works() .image_sizes(&["large"]) .include_sanity_level(false) .send() .expect("Request failed.") .json() .expect("Failed to parse as json.");
work is of type
serde_json::Value, it's up to you to figure out how you want to parse this response for your program.
You may want to refer here for what a response from Pixiv may look like.
- More examples!
- More versatile support for handling and parsing responses (instead of just the raw response)
- More API support (although pixiv doesn't document their public API anywhere to my knowledge...)
HTTP header types
Error returned on failure to authorize with pixiv.
A set of HTTP headers
The Request Method (VERB)
Used to authenticate to the Pixiv servers and construct Pixiv requests through methods creating
Pixiv request. You can create this using
Pixiv request builder. You can create this using any of the provided methods in
Enum to set publicity param.
Enum to set ranking mode param.
Enum to set ranking type param.
Enum to set search mode param.
Enum to set search order param.
Enum to set search period param.