1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
use google_calendar3::{CalendarHub, Result, Error};
use home;
use hyper;
use hyper_rustls;
use tokio;
use yup_oauth2 as oauth2;
use std::fs;
#[tokio::main]
async fn main() {
// let secret: oauth2::ApplicationSecret = Default::default();
let secret = secret_from_file();
let auth = oauth2::InstalledFlowAuthenticator::builder(
secret,
oauth2::InstalledFlowReturnMethod::HTTPRedirect,
).build().await.unwrap();
let hub = CalendarHub::new(
hyper::Client::builder()
.build(hyper_rustls::HttpsConnector::with_native_roots()),
auth,
);
let result = hub.events()
.get("primary", "1uj192r9qtotb6se0rov83ahr6")
.doit()
.await;
match result {
Err(e) => match e {
// The Error enum provides details about what exactly happened.
// You can also just use its `Debug`, `Display` or `Error` traits
Error::HttpError(_)
|Error::Io(_)
|Error::MissingAPIKey
|Error::MissingToken(_)
|Error::Cancelled
|Error::UploadSizeLimitExceeded(_, _)
|Error::Failure(_)
|Error::BadRequest(_)
|Error::FieldClash(_)
|Error::JsonDecodeError(_, _) => println!("{}", e),
},
Ok(res) => println!("Success: {:?}", res),
}
}
fn secret_from_file() -> oauth2::ApplicationSecret {
let f = fs::File::open(
home::home_dir()
.unwrap()
.join(".google-service-cli/calendar3-secret.json"),
).unwrap();
let console_secret: oauth2::ConsoleApplicationSecret = serde_json::from_reader(f).unwrap();
match console_secret.installed {
Some(secret) => secret,
None => todo!(),
}
}
|