18 releases (6 breaking)

0.7.1 Sep 5, 2023
0.6.0 Aug 27, 2023
0.5.9 May 10, 2023

#2 in #twitter

Download history 5/week @ 2023-06-04 14/week @ 2023-06-11 24/week @ 2023-06-18 10/week @ 2023-06-25 25/week @ 2023-07-02 15/week @ 2023-07-23 49/week @ 2023-07-30 30/week @ 2023-08-06 2/week @ 2023-08-13 18/week @ 2023-08-20 41/week @ 2023-08-27 81/week @ 2023-09-03 21/week @ 2023-09-10 22/week @ 2023-09-17

165 downloads per month

MIT license

475KB
14K SLoC

twapi-v2-rs

Twitter API v2 library.

Documentation

  • Request builder
  • Retrive rate limit from response headers
  • Convenience setted parameter methods
  • Bearer authentication(OAuth 2.0 Authorization Code Flow with PKCE)
  • OAuth1.0a authentication(OAuth 1.0a User Contex)
  • Optional retriable and timeout and logging
  • Optional OAuth with web example
  • Streaming example
  • Experimental type support.

Features

default

  • reqwest/default-tls

rustls-tls

  • reqwest/rustls-tls

retry

  • Retriable
  • Timeout
  • Logging

oauth

  • Twitter OAuth

oauth10a

  • Use api by OAuth1.0a

Changes

CHANGELOG.md

Test status

TEST.md

Examples

API(bearer)

use twapi_v2::api::{get_2_tweets_id, BearerAuthentication};

#[tokio::main]
async fn main() {
    let bearer_code = std::env::var("BEARER_CODE").unwrap();
    let auth = BearerAuthentication::new(bearer_code);
    let tweet_id = std::env::var("TWEET_ID").unwrap();
    let res = get_2_tweets_id::Api::open(&tweet_id)
        .execute(&auth)
        .await;
    if let Some((val, rate_limit)) = res {
        println!("{:?}", val);
    }
}

API(OAuth1.0a)

use twapi_v2::api::{get_2_tweets_id, BearerAuthentication};
use twapi_v2::oauth10a::OAuthAuthentication;

#[tokio::main]
async fn main() {
    let auth = OAuthAuthentication::new(
        std::env::var("CONSUMER_KEY").unwrap_or_default(),
        std::env::var("CONSUMER_SECRET").unwrap_or_default(),
        std::env::var("ACCESS_KEY").unwrap_or_default(),
        std::env::var("ACCESS_SECRET").unwrap_or_default(),
    );
    let tweet_id = std::env::var("TWEET_ID").unwrap();
    let res = get_2_tweets_id::Api::open(&tweet_id)
        .execute(&auth)
        .await;
    if let Some((val, rate_limit)) = res {
        println!("{:?}", val);
    }
}

Twitter OAuth Web

cd examples/oauth-web
API_KEY_CODE=XXXX API_SECRET_CODE=XXXX cargo run

http://localhost:3000/

Streaming

cd examples/streaming
BEARER_CODE=XXXXX cargo run

Dependencies

~5–48MB
~759K SLoC