Very basic PoC talking to google API.
This commit is contained in:
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user