-
Notifications
You must be signed in to change notification settings - Fork 11
/
main.rs
60 lines (49 loc) · 1.74 KB
/
main.rs
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
//! This example lists current google calendars
mod calendar_v3_types;
use calendar_v3_types as gcal;
use env_logger;
use async_google_apis_common as common;
use std::sync::Arc;
/// Create a new HTTPS client.
fn https_client() -> common::TlsClient {
let conn = hyper_rustls::HttpsConnectorBuilder::new().with_native_roots().https_or_http().enable_http2().build();
let cl = hyper::Client::builder().build(conn);
cl
}
async fn gcal_calendars(cl: &gcal::CalendarListService) -> anyhow::Result<gcal::CalendarList> {
let params = gcal::CalendarListListParams {
show_deleted: Some(true),
show_hidden: Some(true),
..gcal::CalendarListListParams::default()
};
cl.list(¶ms).await
}
#[tokio::main]
async fn main() {
env_logger::init();
let https = https_client();
// Put your client secret in the working directory!
let sec = common::yup_oauth2::read_application_secret("client_secret.json")
.await
.expect("client secret couldn't be read.");
let auth = common::yup_oauth2::InstalledFlowAuthenticator::builder(
sec,
common::yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
)
.persist_tokens_to_disk("tokencache.json")
.hyper_client(https.clone())
.build()
.await
.expect("InstalledFlowAuthenticator failed to build");
let scopes = vec![
gcal::CalendarScopes::CalendarReadonly,
gcal::CalendarScopes::CalendarEventsReadonly,
gcal::CalendarScopes::Calendar,
gcal::CalendarScopes::CalendarEvents,
];
let mut cl = gcal::CalendarListService::new(https, Arc::new(auth));
cl.set_scopes(scopes.clone());
for cal in gcal_calendars(&cl).await.unwrap().items.unwrap() {
println!("{:?}", cal);
}
}