Module egg_mode::stream [−][src]
Expand description
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 futures::{Stream, TryStreamExt}; let stream = filter() // find tweets mentioning any of the following: .track(&["rustlang", "python", "java", "javascript"]) .start(&token); stream.try_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(()) }).await.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
Represents a bounding box of (longitude, latitude) pairs.
Represents a TwitterStream
before it is started. Use the various methods to build
up the filters on your stream.
A Stream
that represents a connection to the Twitter Streaming API.
Enums
Represents the amount of filtering that can be done to streams on Twitter’s side.
Represents the kinds of messages that can be sent over Twitter’s Streaming API.