29 releases

0.13.0 Jul 17, 2021
0.12.0 Jan 12, 2021
0.11.0 Oct 20, 2020
0.10.0 Jul 11, 2020
0.2.0 Feb 26, 2017

#913 in Web programming

Download history 28/week @ 2024-06-24 2/week @ 2024-07-01 1/week @ 2024-07-08 13/week @ 2024-07-22 389/week @ 2024-07-29 27/week @ 2024-08-05 17/week @ 2024-08-12 10/week @ 2024-09-16 36/week @ 2024-09-23 31/week @ 2024-09-30

77 downloads per month
Used in 2 crates

MIT license

46KB
716 lines

Twitter Stream

Build Status Current Version Documentation

A Rust library for listening on Twitter Streaming API.

Usage

Add this to your Cargo.toml:

[dependencies]
futures = "0.3"
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
twitter-stream = "0.13"

Here is a basic example that prints public mentions to @Twitter in JSON format:

use futures::prelude::*;
use twitter_stream::{Token, TwitterStream};

#[tokio::main]
async fn main() {
    let token = Token::new("consumer_key", "consumer_secret", "access_key", "access_secret");

    TwitterStream::track("@Twitter", &token)
        .try_flatten_stream()
        .try_for_each(|json| {
            println!("{}", json);
            future::ok(())
        })
        .await
        .unwrap();
}

Alternatives

egg-mode, a Twitter API client crate, implements a Streaming API client as well. The following table shows key differences between twitter-stream and egg-mode.

twitter-stream egg-mode
Streaming message type string::String<bytes::Bytes> (raw JSON string) StreamMessage (deserialized message)
REST API integration No Yes
Customizable HTTP client Yes No

If your application don't require explicit control over the raw JSON strings or underlying HTTP client, egg-mode may be a better choice.

License

This project is licensed under the MIT license (LICENSE or https://opensource.org/licenses/MIT) unless explicitly stated otherwise.

Dependencies

~1–13MB
~148K SLoC