raccess-tokentwitter-oauthrtweetr-taskscheduler

Scheduling rtweet::stream_tweets() in R


Attached code works fine for me when manually running it after restarting windows and R - but not when scheduling the task with taskscheduleR package (stops immediately after it starts running, creates file but no content). Might be related to some access-token-issues but I couldn't solve it.

Any ideas...?

##Before restart (manually)...
  library("rtweet")
  appname <- "herr[...]mann"
  key <- "SzA[...]1o7u"
  secret <- "4MtSJom[...]WjdgRUuz"
  twitter_token <- create_token(app = appname, consumer_key = key, 
                                consumer_secret = secret)
  saveRDS(twitter_token, file = "C:/Users/DataMine/Documents/R/twitter_token.rds")

##After restart (scheduled)...
  library("rtweet")
  twitter_token <- readRDS("C:/Users/DataMine/Documents/R/twitter_token.rds")
  test <- stream_tweets(q = "election", file_name = "...", timeout = 60)

Solution

  • Access-token needs to be handed over manually to the token argument...:

    twitter_token <- readRDS("C:/Users/DataMine/Documents/R/twitter_token.rds")
    stream_tweets(q = "ellection", token = twitter_token)
    

    For me, that was the only way to get this thing on schedule (taskscheduleR)...