16.3 Download Data

  • We will download tweets with ‘#auspol’; a popular hashtag used in Australia to talk about current affairs and socio-political issues
  • Example here uses rtweet package to download data
  • After setting up the API
  • Create the token
  • search_tweets can be used without creating the token, it will create a token using the default app for your Twitter account
library(rtweet)

token <- create_token(app = "your_app_name", consumer_key = "your_consumer_key",
    consumer_secret = "your_consumer_secret", access_token = "your_access_token",
    access_secret = "your_access_secret")
  • Use the search_tweets function to download the data, convert to data frame and save
rt = search_tweets(q = "#auspol", n = 15000, type = "recent", include_rts = FALSE,
    since = "2020-09-14")
rt2 = as.data.frame(rt)
saveRDS(rt2, file = "tweets_auspol.rds")