A crate for accessing VK (VKontakte) API in Rust (asynchronously).
Changelog is available here.
api
- works with the API;error
- handles errors that may occur during an API call;methods
- contains API methods;objects
- contains API objects. See also note about objects.
Add the dependency to your project:
Cargo.toml
[dependencies]
rvk = "0.21"
Now you can take a look at rvk
's API documentation to learn more about the available functions.
To use this example, you will also need the tokio
crate for the tokio::main
attribute proc macro.
Cargo.toml
[dependencies]
tokio = { version = "1.0", features = ["full"] }
main.rs
use rvk::{methods::users, objects::user::User, APIClient, Params};
#[tokio::main]
async fn main() {
let api = APIClient::new("your_access_token"); // Create an API Client
let mut params = Params::new(); // Create a HashMap to store parameters
params.insert("user_ids".into(), "1".into());
let res = users::get::<Vec<User>>(&api, params).await;
match res {
Ok(users) => {
let user: &User = &users[0];
println!(
"User #{} is {} {}.",
user.id, user.first_name, user.last_name
);
}
Err(e) => println!("{}", e),
};
}
Due to the nature of the VK API documentation, it is not always clear if the value is always passed or not, and sometimes the data type is not defined.
If you spot any mistakes or bugs, please report them!
There is a feature trace_response
which helps to create reports more informative. If the feature is active the API methods save responses from vk.com into json files.
The rules of saving are:
- if parsing the response failed it is stored into
${RVK_TRACE_DIR}/failed/YY-MM-DD_HH-mm-SS.json
file - otherwise, if
${RVK_TRACE_ALL}=1
the succeeded response is stored into${RVK_TRACE_DIR}/succeeded/YY-MM-DD_HH-mm-SS.json
file