Rust
Rust
Create Google Photos Album
See more Google Photos Examples
Demonstrates how to create a Google Photos album.Chilkat Rust Downloads
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
// Get the previously obtained access token.
// See Get Google Photos Access Token.
let json_token = chilkat::JsonObject::new();
if json_token.load_file("qa_data/tokens/googlePhotos.json").is_err() {
println!("{}", json_token.last_error_text());
return;
}
let http = chilkat::Http::new();
http.set_auth_token(&json_token.string_of("access_token").unwrap_or_default());
// Create an album named "animals"
let json = chilkat::JsonObject::new();
let _ = json.update_string("album.title", "animals");
let resp = chilkat::HttpResponse::new();
if http.http_json("POST", "https://photoslibrary.googleapis.com/v1/albums", &json, "application/json", &resp).is_err() {
println!("{}", http.last_error_text());
return;
}
// Show the response body.
println!("{}", resp.body_str());
// Examine the response status code. Success is indicated by a status code of 200.
println!("response status code: {}", resp.status_code());
let _ = json.load(&resp.body_str());
// Sample response:
// {
// "id": "AKcbugHaQTvUKSi3M2RQxOhxhdEaLc5mfUcqFoIU_kpQaROyUD70BcFt7_mnz5PcwwsjPKeKnLHN",
// "title": "animals",
// "productUrl": "https://photos.google.com/lr/album/AKcbugHaQTvUKSi3M2RQxOhxhdEaLc5mfUcqFoIU_kpQaROyUD70BcFt7_mnz5PcwwsjPKeKnLHN",
// "isWriteable": true
// }
// Use this online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON
let id = json.string_of("id").unwrap_or_default();
let title = json.string_of("title").unwrap_or_default();
let product_url = json.string_of("productUrl").unwrap_or_default();
let is_writeable = json.bool_of("isWriteable");
println!("id = {}", id);