Skip to content

Instantly share code, notes, and snippets.

@sudevschiz
Created April 9, 2018 14:31
Show Gist options
  • Save sudevschiz/51630fd7c7898682dcc7c935b3af60a5 to your computer and use it in GitHub Desktop.
Save sudevschiz/51630fd7c7898682dcc7c935b3af60a5 to your computer and use it in GitHub Desktop.
library(streamR)
library(ROAuth)
setwd("~/tweet_miner_boy/")
# The following four lines assign the right values to the variables that
# are needed for the API call.
requestURL <- "https://api.twitter.com/oauth/request_token"
accessURL <- "https://api.twitter.com/oauth/access_token"
authURL <- "https://api.twitter.com/oauth/authorize"
consumerKey <- "FILL-THIS"
consumerSecret <- "FILL-THIS"
# PIN has to be entered in the R-console.
my_oauth <- OAuthFactory$new(consumerKey = consumerKey,
consumerSecret = consumerSecret,
requestURL = requestURL,
accessURL = accessURL,
authURL = authURL)
#my_oauth$handshake(cainfo = system.file("CurlSSL", "cacert.pem", package = "RCurl"))
# Once the connection is established we can save it so that we do not have
# repeat this process.
#save(my_oauth, file = "my_oauth.Rdata")
load("my_oauth.Rdata")
track = "Google"
file = paste0("tweets",track,".json", collapse = "_")
follow = NULL
loc = c(-121.6,11.3,-78.4,33.3)
lang = NULL
minutes = .30
time = 60*minutes
tweets = NULL
filterStream(file.name = file,
track = track,
follow = follow,
locations = loc,
language = lang,
timeout = time,
tweets = tweets,
oauth = my_oauth,
verbose = TRUE)
tweets.df <- parseTweets(file)
write.csv(tweets.df,paste0("tweets_",track,as.integer(Sys.time()),".csv", collapse = "_"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment