How To Extract Twitter Tweets In R
Mine Twitter Tweets using R

PREREQUISITES:
1. Installed R & RStudio , you can see a video explaining in detail how to do this.
2. A Twitter application and account to extract tweets
3. A Twitter Developers login ID & Password
STEPS:
1. Create a Twitter Application
Sign in using your Twitter Account

You should’ve been directed to the twitter app. Now click “Create New App”

Create an application

NOTE: If you haven’t already, then you may need to add your phone number to your twitter profile. Go to settings and privacy→ Mobile

Go to Keys and Access Tokens

Write down the Consumer key (API Key) and the Consumer secret (API Secret)

Create your access token by clicking Create my access token

Once the access token is created, write down the Access Token and the Access Token Secret

2. Install and Load R packages
Open RStudio or whatever IDE you are using for R, and install and load the following two packages. If you need an IDE here is a video showing how to install RStudio. If you don’t know how to install packages on RStudio, here is a video on how to do that as well here.
twitteR: Provides an interface to the Twitter web API.
#Install and Load R packagesinstall.packages("twitteR")
library("twitteR")
3. Setup Twitter Authentication
Use your consumer key, consumer secret, access token, and access secret that you wrote down in the earlier steps from the above, and replace ‘xxxxxxxxxxx’ with the appropriate values.
consumerKey=’XXXXXXXXXXXXXXXXXXXXXXXX’
consumerSecret=’XXXXXXXXXXXXXXXXXXXXXX’accessToken=’XXXXXXXXXXXXXXXXXXXX’
accessTokenSecret= ‘XXXXXXXXXXXXXXXXXXXXXXXXXX’setup_twitter_oauth(consumerKey,consumerSecret,accessToken,accessTokenSecret)
4. Extract Tweets
The searchTwitter function code below will return 3 tweets about the nba in english.
n= the maximum number of tweets to return
lang = restrict tweets to the given language
SearchString = “nba”
searchTwitter("nba", n=3, lang="en")
Get the R code here on my GitHub:
Resources:
1) Sentiment Analysis Evaluate Neg and Pos words
2) Twitter Analytics Using R
3) Sentiment Analysis Bernie Sanders
4) Getting Started with Twitter Analysis