twitter-stream

Crates.iotwitter-stream
lib.rstwitter-stream
version0.13.0
sourcesrc
created_at2017-01-23 10:59:32.626596
updated_at2021-07-17 09:02:20.104858
descriptionA library for listening on Twitter Streaming API.
homepagehttps://github.com/tesaguri/twitter-stream-rs
repositoryhttps://github.com/tesaguri/twitter-stream-rs
max_upload_size
id8192
size94,876
Daiki Mizukami (tesaguri)

documentation

https://docs.rs/twitter-stream/0.13.0/twitter_stream/

README

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.

Commit count: 397

cargo fmt