[−][src]Module egg_mode::stream
Access to the Streaming API.
The Streaming API gives real-time access to tweets, narrowed by search phrases, user id or location. A standard user is able to filter by up to 400 keywords, 5,000 user ids and 25 locations. See the official documentation for more details.
Example
use egg_mode::stream::{filter, StreamMessage}; use tokio::runtime::current_thread::block_on_all; use futures::Stream; let stream = filter() // find tweets mentioning any of the following: .track(&["rustlang", "python", "java", "javascript"]) .start(&token); block_on_all(stream.for_each(|m| { // Check the message type and print tweet to console if let StreamMessage::Tweet(tweet) = m { println!("Received tweet from {}:\n{}\n", tweet.user.unwrap().name, tweet.text); } futures::future::ok(()) })).expect("Stream error");
Connection notes
To maintain a stable streaming connection requires a certain amount of effort to take account of random disconnects, networks resets and stalls. The key points are:
- The Twitter API sends a Ping message every 30 seconds of message inactivity. So set a timeout such that after (say) 1 minute of inactivity, the client bounces the connection. This will protect against network stalls
- Twitter will rate-limit reconnect attempts. So attempt conenctions with a linear or exponential backoff strategy
- In the case of an unreliable connection (e.g. mobile network), fall back to the polling API
The official guide has more information.
Structs
BoundingBox | Represents a bounding box of (longitude, latitude) pairs. |
StreamBuilder | Represents a |
TwitterStream | A |
Enums
FilterLevel | Represents the amount of filtering that can be done to streams on Twitter's side. |
StreamMessage | Represents the kinds of messages that can be sent over Twitter's Streaming API. |
Functions
filter | Begins building a request to a filtered public stream. |
sample | Opens a |