Move to std::futures to support async/await.

This commit is contained in:
Glenn Griffin
2019-11-07 14:23:40 -08:00
parent 01e7a7f437
commit 93cbd91341
16 changed files with 923 additions and 1148 deletions

View File

@@ -1,20 +1,20 @@
use futures::prelude::*;
use yup_oauth2::{self, Authenticator, DeviceFlow, GetToken};
use std::path;
use tokio;
fn main() {
#[tokio::main]
async fn main() {
let creds = yup_oauth2::read_application_secret(path::Path::new("clientsecret.json"))
.expect("clientsecret");
let mut auth = Authenticator::new(DeviceFlow::new(creds))
let auth = Authenticator::new(DeviceFlow::new(creds))
.persist_tokens_to_disk("tokenstorage.json")
.build()
.expect("authenticator");
let scopes = vec!["https://www.googleapis.com/auth/youtube.readonly"];
let mut rt = tokio::runtime::Runtime::new().unwrap();
let fut = auth.token(scopes).and_then(|tok| Ok(println!("{:?}", tok)));
println!("{:?}", rt.block_on(fut));
match auth.token(scopes).await {
Err(e) => println!("error: {:?}", e),
Ok(t) => println!("token: {:?}", t),
}
}