Since the free Twitter API only allows you to search the last 7 days worth of data I am trying to automatically set the dates for those 7 days. When I leave the date fields blank I get random historical tweets.
#### Pepsi
#Dates for API
s <- as.Date(Sys.Date()-7, format = "%Y/%m/%d")
e <- as.Date(Sys.Date(), format = "%Y/%m/%d")
#Pepsi Twitter Data
pepsitweet <- searchTwitter("Pepsi",n=1000,lang="en", since = "s", until = "e")
tweets1 <- twListToDF(pepsitweet)
Error
1000 tweets were requested but the API can only return 0
Error in as.POSIXlt.character(x, tz, …) :
character string is not in a standard unambiguous format
2
Answers
Don’t put quotes around the variables
s
ande
. R is interpreting them as strings.You might also want to check out Mike Kearney’s rtweet package, which seems to be much smoother than twitteR: https://cran.r-project.org/web/packages/rtweet/vignettes/intro.html
I’ve had a cron job mining tweets on a daily basis since November and it’s performed beautifully.