-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathuserdata.rs
More file actions
49 lines (42 loc) · 1.51 KB
/
userdata.rs
File metadata and controls
49 lines (42 loc) · 1.51 KB
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
use critter::{auth::TwitterAuth, TwitterClient};
use std::env;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let auth = TwitterAuth::from_oa1uc(
&env::var("CONSUMER_KEY").unwrap(),
&env::var("CONSUMER_SECRET").unwrap(),
&env::var("ACCESS_TOKEN").unwrap(),
&env::var("ACCESS_TOKEN_SECRET").unwrap(),
);
let mut twitter = TwitterClient::new(auth)?;
// Print all the default fields
match twitter.me(None).await {
Ok(data) => println!(
"My name is {} and my username is {}. Also, my id is {}.",
data.name(),
data.username(),
data.id()
),
Err(e) => println!("Error: {}", e), // Can be something like ratelimit
}
// Request the description
match twitter.me(Some(&["description"])).await {
Ok(data) => println!("My description is \"{}\"", data.description()),
Err(e) => println!("Error: {}", e),
}
// Request the date your account was created at
match twitter.me(Some(&["created_at"])).await {
Ok(data) => println!("I made my account on {}", data.created_at()),
Err(e) => println!("Error: {}", e),
}
// Request multiple fields
match twitter.me(Some(&["description", "created_at"])).await {
Ok(data) => println!(
"My description is \"{}\" and I made my account on {}",
data.description(),
data.created_at()
),
Err(e) => println!("Error: {}", e),
}
Ok(())
}