get_tweets {Twitmo}R Documentation

Sample tweets by streaming or searching

Description

Collect Tweets via streaming or searching.

Usage

get_tweets(
  method = "stream",
  location = c(-180, -90, 180, 90),
  timeout = Inf,
  keywords = "",
  n_max = 100L,
  file_name = NULL,
  ...
)

Arguments

method

Character string. Supported methods are streaming and searching. The default method is streaming method = 'stream'. This is the recommended method as it allows to collect larger volumes of data over time. Use method = 'search' if you want to collect Tweets from the past 9 days.

location

Character string of location to sample from. Can be a three letter country code i.e. "USA" or a city name like "berlin". Use Twitmo:::bbox_country for all supported country locations or rtweet:::citycoords for a list of supported cities. Alternatively, use a vector of doubles with four latitude/longitude bounding box points provided via a vector of length 4, in the following format c(sw.long, sw.lat, ne.long, ne.lat) e.g., c(-125, 26, -65, 49).

timeout

Integer. Limit streaming time in seconds. By default will stream indefinitely until user interrupts by pressing [ctrl + c].

keywords

Character string of keywords provided via a comma separated character string. Only for searching Tweets.If you want to stream Tweets for a certain location AND filter by keywords use the location parameter and after sampling use the filter_tweets function. If you are using the search method instead of streaming keywords WILL work together with a location but will yield only a very limited number of Tweets.

n_max

Integer value. Only applies to the search method. Limit how many Tweets are collected.

file_name

Character string of desired file path and file name where Tweets will be saved. If not specified, will write to stream_tweets.json in the current working directory.

...

Additional arguments passed to stream_tweets or search_tweets.

Details

A function that calls on stream_tweets and search_tweets (depending on the specified method) and is specifically tailored for sampling geo-tagged data. This function provides supports additional arguments like location for convenient sampling of geo-tagged Tweets. Tweets can be searched up to 9 days into the past.

Value

Either a json file in the specified directory.

References

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

See Also

stream_tweets, search_tweets

Examples

## Not run: 

# live stream tweets from Germany for 60 seconds and save to current working directory
get_tweets(method = "stream",
           location = "DEU",
           timeout = 60,
           file_name = "german_tweets.json")

# OR
# live stream tweets from berlin for an hour
get_tweets(method = "stream",
           location = "berlin",
           timeout = 3600,
           file_name = "berlin_tweets.json")

# OR
# use your own bounding box coordinates to strean tweets indefinitely (interrupt to stop)
get_tweets(method = 'stream',
           location = c(-125, 26, -65, 49),
           timeout = Inf)


## End(Not run)

[Package Twitmo version 0.1.2 Index]