########################################################################################## ## Collecting Twitter Data from Streaming API ## To run this script, you need to generate your own "consumerKey", "consumerSecret", and ## an oAuth token by ##registering your application with Twitter. It is a simple process, ## just pick a name for your application. ##Register it here: https://dev.twitter.com/apps ## ## Documentation of Twitter Streaming API: ## https://dev.twitter.com/docs/streaming-apis/streams/public ## https://dev.twitter.com/docs/auth/authorizing-request ## http://www.foundations-edge.com/blog/oauth_in_R.html ## https://dev.twitter.com/docs/streaming-apis/processing ## ########################################################################################## ## Change working directory # Load required libraries library(RCurl) library(ROAuth) library(streamR) library(twitteR) library(rtweet) #download certificate needed for authentication, creates a certificate file on desktop download.file(url="http://curl.haxx.se/ca/cacert.pem", destfile="cacert.pem") # Twitter configuration # Set all the Configuration details to authorize your application to access Twitter data. consumer_key <- "XXXX" #replace with your key consumer_secret <- "XXXX" #replace with your secret access_token <- "XXXX" #replace with your access token access_token_secret <- "XXXX" #replace with your access token secret #obtain oauth by handshaking and save the oauth to the local disk for future connections setup_twitter_oauth(consumer_key, consumer_secret, access_token, access_token_secret) tw <- twitteR::searchTwitter('#realDonaldTrump + #HillaryClinton', n = 1e4, since = '2019-02-15', retryOnRateLimit = 1e3) tw2 <- twitteR::searchTwitter('#realDonaldTrump', n = 1e4, since = '2019-02-15', retryOnRateLimit = 1e3) tweets <- twitteR::twListToDF(tw)