stream_tweets: Collect a live stream of Twitter data

Description Usage Arguments Value References Examples

View source: R/stream.R

Description

Streams public statuses to a file via one of the following four methods:

  1. Sampling a small random sample of all publicly available tweets

  2. Filtering via a search-like query (up to 400 keywords)

  3. Tracking via vector of user ids (up to 5000 user_ids)

  4. Location via geo coordinates (1-360 degree location boxes)

Learn more in vignette("stream", package = "rtweet")

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
stream_tweets(
  q = "",
  timeout = 30,
  parse = TRUE,
  token = NULL,
  file_name = NULL,
  verbose = TRUE,
  append = TRUE,
  ...
)

Arguments

q

Query used to select and customize streaming collection method. There are four possible methods:

  1. The default, q = "", returns a small random sample of all publicly available Twitter statuses.

  2. To filter by keyword, provide a comma separated character string with the desired phrase(s) and keyword(s).

  3. Track users by providing a comma separated list of user IDs or screen names.

  4. Use four latitude/longitude bounding box points to stream by geo location. This must be provided via a vector of length 4, e.g., c(-125, 26, -65, 49).

timeout

Integer specifying number of seconds to stream tweets for. Stream indefinitely with timeout = Inf.

The stream can be interrupted at any time, and file_name will still be valid file.

parse

Use FALSE to opt-out of parsing the tweets.

token

Expert use only. Use this to override authentication for a single API call. In most cases you are better off changing the default for all calls. See auth_as() for details.

file_name

Character with name of file. If not specified, will write to stream_tweets.json in the current working directory.

verbose

If TRUE, display a progress bar.

append

If TRUE, will append to the end of file_name; if FALSE, will overwrite.

...

Other arguments passed in to query parameters.

Value

A tibble with one row per tweet

References

https://developer.twitter.com/en/docs/twitter-api/v1/tweets/sample-realtime/api-reference/get-statuses-sample, https://developer.twitter.com/en/docs/twitter-api/v1/tweets/filter-realtime/overview

Stream: https://developer.twitter.com/en/docs/twitter-api/v1/tweets/sample-realtime/api-reference/get-statuses-sample Filter: https://developer.twitter.com/en/docs/twitter-api/v1/tweets/filter-realtime/api-reference/post-statuses-filter

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
## Not run: 
# stream tweets mentioning "election" for 10 seconds
e <- stream_tweets("election", timeout = 10)
e

# Download another 10s worth of data to the same file
e <- stream_tweets("election", timeout = 10)

# stream tweets about continential USA for 5 minutes
usa <- stream_tweets(lookup_coords("usa"), file_name = "usa.json", timeout = 300)


## End(Not run)

mkearney/rtweet documentation built on Sept. 29, 2021, 12:01 p.m.