library(twitteR) source("~/OneDriveBusiness/Projects/Authentications/twitterOAuth.R") setup_twitter_oauth(consumer_key, consumer_secret, access_token, access_secret)
Now we're authenticated and ready to go, we can call
homeTimeline() with the argument
retryOnRateLimit set high. Note that twitter will only allow you to retrieve so many tweets from your feed so if you want recent tweets get them while you still can.
timeLine <- homeTimeline(n = 800, retryOnRateLimit = 1000)
Now we can use some of the date functionality to subset the tweets retaining only those in the relevant time period.
beginning <- as.POSIXct("2015-12-07 09:00:00 UTC") end <- as.POSIXct("2015-12-07 11:00:00 UTC") times <- lapply(timeLine, function(x) x$created) these <- which(times > beginning & times < end) myMorningTweets <- timeLine[these]
Now that we have the subset that we want, we can use the provided function to turn the list like object into a data frame and store it for later.
myMorningTweetsDF <- twListToDF(myMorningTweets) write.csv(myMorningTweetsDF, "data/myMorningTweets.csv")