rvk
A crate for accessing VK (VKontakte) API in Rust (synchronously).
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
toml
[dependencies]
rvk = "0.13"
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 serde_json
crate to deserialize the API response:
Cargo.toml
toml
[dependencies]
serde_json = "1.0"
main.rs
```rust
use rvk::{methods::*, objects::user::User, APIClient, Params};
use serdejson::fromvalue;
fn main() { let api = APIClient::new("youraccesstoken"); // 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(&api, params);
match res {
Ok(v) => { // v is `serde_json::Value`
let users: Vec<User> = from_value(v).unwrap();
let 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!