library("quotefinder")
library("rtweet")
library("dplyr")
twitter_token <- readRDS(file = "twitter_token.rds")
There are three main ways to retrieve tweets using Twitter’s API:
By itself, the excellent rtweet
package commonly used to interact with the Twitter APIs with R, does not provide convenience functions to cache and store tweets, leaving this to the user.
The present quotefinder
package provides such functions in order to facilitate collecting and pre-processing tweets in order to feed them to the QuoteFinder app. All retrieved tweets are stored in dated local sub-folders.
The following command will download all available tweets for the given users and store them locally. If they have been previously downloaded, it will download only newer tweets.
When there is a need to collect regularly tweets from hundreds or thousands of users, this approach quickly becomes impractical, as it is easier to hit the limits allowed by Twitter APIs.
An easy solution is to create a list of users, and then make a single request to get recent tweets for all accounts included in the list.1
It is easy to create new lists by using rtweet
s post_list()
function.↩