Crates.io | twitter-stream-message |
lib.rs | twitter-stream-message |
version | 0.3.0 |
source | src |
created_at | 2017-06-16 09:59:10.492755 |
updated_at | 2018-06-01 04:12:39.67309 |
description | Types for Twitter Streaming API's messages. |
homepage | https://github.com/dmizuk/twitter-stream-rs |
repository | https://github.com/dmizuk/twitter-stream-rs |
max_upload_size | |
id | 19181 |
size | 85,211 |
A Rust library for listening on Twitter Streaming API.
This library requires Rust 1.21 or later.
Add this to your Cargo.toml
:
[dependencies]
twitter-stream = "0.5"
and this to your crate root:
extern crate twitter_stream;
Here is a basic example that prints public mentions @Twitter in JSON format:
extern crate futures;
extern crate tokio_core;
extern crate twitter_stream;
use futures::{Future, Stream};
use tokio_core::reactor::Core;
use twitter_stream::{Token, TwitterStreamBuilder};
fn main() {
let token = Token::new("consumer_key", "consumer_secret", "access_key", "access_secret");
let mut core = Core::new().unwrap();
let future = TwitterStreamBuilder::filter(&token).handle(&core.handle())
.replies(true)
.track(Some("@Twitter"))
.listen()
.flatten_stream()
.for_each(|json| {
println!("{}", json);
Ok(())
});
core.run(future).unwrap();
}