23 releases

0.0.26 Apr 6, 2021
0.0.25 Apr 2, 2021
0.0.22 Mar 17, 2021
0.0.19 Feb 27, 2021
0.0.4 May 31, 2020
Download history 13/week @ 2021-01-01 19/week @ 2021-01-15 22/week @ 2021-01-22 75/week @ 2021-01-29 493/week @ 2021-02-05 740/week @ 2021-02-12 483/week @ 2021-02-19 461/week @ 2021-02-26 473/week @ 2021-03-05 420/week @ 2021-03-12 656/week @ 2021-03-19 659/week @ 2021-03-26 452/week @ 2021-04-02 317/week @ 2021-04-09

1,595 downloads per month
Used in 2 crates

MIT license

84KB
1.5K SLoC

kuon

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

~7–10MB
~222K SLoC