Rust
Rust
Dropbox: Get Space Usage
See more Dropbox Examples
Demonstrates how to get the Dropbox space usage information for the current user's account.Chilkat Rust Downloads
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let rest = chilkat::Rest::new();
// Connect to the www.dropbox.com endpoint.
let b_tls = true;
let port = 443;
let b_auto_reconnect = true;
if rest.connect("api.dropboxapi.com", port, b_tls, b_auto_reconnect).is_err() {
println!("{}", rest.last_error_text());
return;
}
let _ = rest.add_header("Authorization", "Bearer DROPBOX-ACCESS-TOKEN");
let Ok(response_str) = rest.full_request_no_body("POST", "/2/users/get_space_usage") else {
println!("{}", rest.last_error_text());
return;
};
// Success is indicated by a 200 response status code.
if rest.response_status_code() != 200 {
// Examine the request/response to see what happened.
println!("response status code = {}", rest.response_status_code());
println!("response status text = {}", rest.response_status_text());
println!("response header: {}", rest.response_header());
println!("response body (if any): {}", response_str);
println!("---");
println!("LastRequestStartLine: {}", rest.last_request_start_line());
println!("LastRequestHeader: {}", rest.last_request_header());
return;
}
let json_response = chilkat::JsonObject::new();
let _ = json_response.load(&response_str);
json_response.set_emit_compact(false);
println!("{}", json_response.emit().unwrap_or_default());
// {
// "used": 3032115,
// "allocation": {
// ".tag": "individual",
// "allocated": 2147483648
// }
// }
//