Skip to content

Instantly share code, notes, and snippets.

@dermesser
Created April 16, 2016 14:12
Show Gist options
  • Save dermesser/8c915ec4c88ee8e8927e7d40b276ca52 to your computer and use it in GitHub Desktop.
Save dermesser/8c915ec4c88ee8e8927e7d40b276ca52 to your computer and use it in GitHub Desktop.
Example for installed flow with yup-oauth2
fn read_client_secret(file: &str) -> ApplicationSecret {
use std::fs::{File, OpenOptions};
use std::io::Read;
let mut secret = String::new();
OpenOptions::new().read(true).open(file).unwrap().read_to_string(&mut secret);
let consappsec: ConsoleApplicationSecret = serde_json::from_str(secret.as_str()).unwrap();
consappsec.installed.unwrap()
}
fn main() {
let secret = read_client_secret("client_secret.json");
let mut client = hyper::Client::new();
let mut auth =
Authenticator::new(&secret,
DefaultAuthenticatorDelegate,
&mut client,
<MemoryStorage as Default>::default(),
Some(FlowType::InstalledInteractive)); // This is the main change!
let mut hub = Drive::new(hyper::Client::new(), auth);
match hub.files().list().q("'root' in parents and not trashed").doit() {
Ok(o) => println!("{:?}", o),
Err(e) => println!("{}", e)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment