stream {rtweet} | R Documentation |
Streaming
Description
Open a streaming connection with Twitter and stores tweets for as long as you wish.
Usage
filtered_stream(
timeout,
file = tempfile(),
expansions = NULL,
fields = NULL,
...,
token = NULL,
append = TRUE,
parse = TRUE
)
stream_add_rule(query, dry = FALSE, token = NULL)
stream_rm_rule(query, dry = FALSE, token = NULL)
sample_stream(
timeout,
file = tempfile(),
expansions = NULL,
fields = NULL,
...,
token = NULL,
parse = TRUE,
append = TRUE
)
Arguments
timeout |
time, in seconds, of the recording stream. |
file |
Path to a file where the raw streaming should be stored. |
expansions |
Set |
fields |
Set |
... |
Other parameters passed to the body of the request. |
token |
These endpoints only accept a bearer token (can be created via
|
append |
Append streaming to the file? Default does but it is recommended to have a new file for each call. |
parse |
If |
query |
If
|
dry |
Check if the addition or removal of the rule works. |
Details
The connection can be left open as long as you wish, the data is appended to the file provided. Be aware that the stream might have incomplete records (you won't be able to read directly from the json file). One tweet might belong to multiple rules.
Value
The records in the streaming.
Functions
-
filtered_stream()
: Start a filtered stream according to the rules. -
stream_add_rule()
: Add rules for the filtered streaming. -
stream_rm_rule()
: Remove rules from the filtered streaming -
sample_stream()
: Retrieve a sample of the tweets posted.
See Also
Rules for filtered stream: https://developer.twitter.com/en/docs/twitter-api/tweets/filtered-stream/integrate/build-a-rule
Sampled stream: https://developer.twitter.com/en/docs/twitter-api/tweets/volume-streams/api-reference/get-tweets-sample-stream
Filtered stream: https://developer.twitter.com/en/docs/twitter-api/tweets/filtered-stream/api-reference/get-tweets-search-stream
Examples
# Requires a bearer token
if (FALSE) {
# How many rules do we have
stream_add_rule(NULL)
# Add new rule
new_rule <- stream_add_rule(list(value = "#rstats", tag = "rstats"))
new_rule
# Open filtered streaming connection for 30s
filtered_stream(file = tempfile(), timeout = 30, parse = FALSE)
# Remove rule
stream_rm_rule(ids(new_rule))
# Open random streaming connection
sample_stream(file = tempfile(), timeout = 3, parse = FALSE)
}