Very basic PoC talking to google API.

This commit is contained in:
Bill Thiede 2020-02-03 22:33:09 -08:00
commit 10d8ec406f
4 changed files with 1773 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
/target
auth/

1721
Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

12
Cargo.toml Normal file
View File

@ -0,0 +1,12 @@
[package]
name = "photosync"
version = "0.1.0"
authors = ["Bill Thiede <git@xinu.tv>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
yup-oauth2 = "^3.1"
google_api_auth = { git = "https://github.com/google-apis-rs/generator", features = ["with-yup-oauth2"] }
google-photoslibrary1 = { path = "../google-api-photoslibrary" }

38
src/main.rs Normal file
View File

@ -0,0 +1,38 @@
use std::path::Path;
use google_api_auth;
use google_photoslibrary1;
use yup_oauth2::GetToken;
use yup_oauth2::{Authenticator, InstalledFlow};
fn main() {
// Read application secret from a file. Sometimes it's easier to compile it directly into
// the binary. The clientsecret file contains JSON like `{"installed":{"client_id": ... }}`
let credentials = "/home/wathiede/src/xinu.tv/photosync/auth/oob-credentials.json";
let secret = yup_oauth2::read_application_secret(Path::new(credentials)).expect(credentials);
// Create an authenticator that uses an InstalledFlow to authenticate. The
// authentication tokens are persisted to a file named tokencache.json. The
// authenticator takes care of caching tokens to disk and refreshing tokens once
// they've expired.
let auth = Authenticator::new(InstalledFlow::new(
secret,
yup_oauth2::InstalledFlowReturnMethod::Interactive,
))
.persist_tokens_to_disk("/tmp/tokencache.json")
.build()
.unwrap();
let scopes = vec!["https://www.googleapis.com/auth/photoslibrary.readonly".to_string()];
let auth = google_api_auth::yup_oauth2::from_authenticator(auth, scopes);
let client = google_photoslibrary1::Client::new(auth);
for album in client
.shared_albums()
.list()
.iter_shared_albums_with_all_fields()
{
println!("album: {:?}", album);
}
}