#twitter #oauth

twapi

A simple Twitter library. This is easy for customize.

12 unstable releases (5 breaking)

0.6.0 Feb 1, 2020
0.5.2 Oct 10, 2019
0.5.0 Jun 27, 2019
0.4.1 May 13, 2018
0.4.0 Mar 23, 2018

#117 in Web programming

Download history 84/week @ 2020-04-24 53/week @ 2020-05-01 76/week @ 2020-05-08 95/week @ 2020-05-15 52/week @ 2020-05-22 80/week @ 2020-05-29 40/week @ 2020-06-05 54/week @ 2020-06-12 58/week @ 2020-06-19 70/week @ 2020-06-26 62/week @ 2020-07-03 56/week @ 2020-07-10 34/week @ 2020-07-17 31/week @ 2020-07-24 34/week @ 2020-07-31 68/week @ 2020-08-07

332 downloads per month

MIT/Apache

28KB
736 lines

twapi-rs

A simple Twitter library. This is easy for customize.

Documentation

Description

twapi-rs* is is a simple Twitter library. This is easy for customize.

Features

  • Application Only Authentication
  • User Authentication
  • JSON support(dm_event, welcome_message, media_metadata)
  • Oauth1.0 Authentication
  • Media Upload
  • Account Activity API
  • OAuth Web Application Example
  • Accout Activity Web Application Example
  • Async/Await(If you want sync executing, you use twapi-ureq.)
  • Any Twitter API Exucutable (maybe...)

Examples

use twapi::Twapi;

#[tokio::main]
async fn main() {
    // Application Only Authentication Sample
    let consumer_key = "xxx";
    let consumer_secret = "xxx";
    let applicaiton_auth = twapi::ApplicationAuth::new(
        &twapi::oauth2::get_bearer_token(consumer_key, consumer_secret).unwrap()
    );
    let res = applicaiton_auth.get_search_tweets(
        &vec![("q", "新宿"), ("count", "2")]
    ).await.unwrap();
    println!("{:?}", res);

    // Custmize Sample. Any API Executable!
    let res: serde_json::Value = applicaiton_auth.get(
        "https://api.twitter.com/1.1/statuses/user_timeline.json",
        &vec![("screen_name", "aoyagikouhei"), ("count", "2")]
    ).await.unwrap().json().await.unwrap();
    println!("{:?}", res);

    // JSON Sample
    let user_auth = twapi::UserAuth::new(
        "xxx",
        "xxx",
        "xxx",
        "xxx"
    );
    let data = r#"{
        "event": {
            "type": "message_create",
            "message_create": {
                "target": {
                    "recipient_id": "19522946"
                },
                "message_data": {
                    "text": "予定表〜①ハンカクだ!"
                }
            }
        }
    }"#;
    let v : serde_json::Value = serde_json::from_str(data).unwrap();
    let res = user_auth.post_direct_messages_events_new(&v).await;
    println!("{:?}", res);

    // Media Upload
    let res = user_auth.post_media_upload_chunk("test.mp4", "video/mp4", "tweet_video", None).await;
    println!("{:?}", res);
}

Dependencies

~9–12MB
~239K SLoC