First,we need to download R to our local computer from https://cran.r-project.org/ CRAN (Comprehensive R Archive Network).Download the package that applies to your computer and follow the prompts to install.
Next we need to download and install R studio from https://www.rstudio.com/products/rstudio/download/ . Select the free R studio Desktop open source lince and choose the package that applies to your computer.
In order to access Twitter Search or Streaming API, we need to get 4 pieces of information from Twitter: API key, API secret, Access token and Access token secret. You can obtain this information by following the steps below:
Once you have obtained the four authentication keys from twitter, you can begin to search for specific keywords of hastags of interest.In the code snippet below, we have extracted two hundred tweets with the keyword “upwork”. These variables can be adjusted as necessary.
#install relevant packages
install.packages("twitteR")
install.packages("ROAuth")
library(twitteR)
library(ROAuth)
#get authentication from Twitter
consumerKey<- "xxxxxxxxxxxxx"
consumerSecret<-"xxxxxxxxxxxxxx"
accessToken<-"xxxxxxxxx"
accessSecret<-"xxxxxxxxxxxx"
setup_twitter_oauth (consumerKey, consumerSecret, accessToken, accessSecret) # authenticate
#search for tweets by keyword
tweets<-searchTwitter("upwork", n=200, lang=NULL, since=NULL, until=NULL, locale=NULL, geocode=NULL, sinceID=NULL, maxID=NULL,
resultType=NULL, retryOnRateLimit=120)
#Put the tweets in a data frame
tweets<-twListToDF(tweets)
#write out to a csv
write.csv(tweets, file="filename.csv")