24 releases
0.0.27 | May 6, 2021 |
---|---|
0.0.26 | Apr 6, 2021 |
0.0.22 | Mar 17, 2021 |
0.0.19 | Feb 27, 2021 |
0.0.4 | May 31, 2020 |
#514 in Authentication
Used in 2 crates
86KB
1.5K
SLoC
Kuon
Twitter Client Library written in Rust.
inspired by anaconda
Example
let builder = kuon::TwitterAPI::builder()
.access_token("access_token")
.access_token_secret("access_token_secret")
.api_key("api_key")
.api_secret_key("api_secret_key");
let api = builder.build().await?;
let res = api.search_tweets().q("rust").send().await?;
let res = api.favorite().id(0).send().await?;
let res = api.retweet().id(0).send().await?;
Shord-hand
// Please set API_KEY, API_SECRET_KEY, ACCESS_TOKEN, ACCESS_TOKEN_SECRET in your environment
let api = kuon::TwitterAPI::new_using_env().await?;
let res = api.search_tweets().q("rust").send().await?;
for tweet in res.statuses {
println!("{}", tweet.text);
}
Advanced Type-safe Usage
use anyhow::Result;
#[tokio::main]
async fn main() -> Result<()> {
// Please set API_KEY, API_SECRET_KEY, ACCESS_TOKEN, ACCESS_TOKEN_SECRET in environment
let api: kuon::TwitterAPI = kuon::TwitterAPI::new_using_env().await?;
let res = api
.search_tweets()
.q("rust")
// .geocode("geocode")
// .lang("lang")
// .locale("locale")
// .result_type("result_type")
// .count(100)
// .until("2000-01-01")
// .since_id(0)
// .max_id(100000000)
// .include_entities(true)
.send()
.await;
match res {
Ok(search_result) => {
for tweet in search_result.statuses {
println!("{}", tweet.text);
}
}
Err(kuon::Error::TwitterAPIError(e, param_str)) => {
// You can confirm a error originated from Twitter API.
println!("{}", param_str);
assert!(e.errors.len() > 0)
}
Err(kuon::Error::HTTPRequestError(e)) => {
println!("{}", e);
// Do something!
}
_ => panic!("Unexpected error!"),
}
Ok(())
}
See more details for /examples
.
This crate is named after Japanese Virtual YouTuber Chitose Kudou
Dependencies
~8–20MB
~282K SLoC