Very basic PoC talking to google API.
This commit is contained in:
commit
10d8ec406f
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
/target
|
||||
auth/
|
||||
1721
Cargo.lock
generated
Normal file
1721
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
12
Cargo.toml
Normal file
12
Cargo.toml
Normal 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
38
src/main.rs
Normal 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);
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user