What you need
- ROAuth package
- twitteR package
- App in twitter to get consumer key and consumer secret.
To Create an App in Twitter
Goto Manage Apps in the bottom
Create App
To Access Tweets
To access tweets from R, you will need the consumer key and consumer secret of your app,which you can access from ‘Manage Apps’ in dev.twitter.com
Once that is done download “cacert.pm” file
download.file (url="http://curl.haxx.se/ca/cacert.pem",destfile="cacert.pem")
Create Twitter Authentication Credential Object
cred <- OAuthFactory$new (consumerKey, consumerSecret, requestURL='https://api.twitter.com/oauth/request_token', accessURL='https://api.twitter.com/oauth/access_token', authURL='https://api.twitter.com/oauth/authorize')
cred$handshake (cainfo="cacert.pem") #handshake
This will prompt you for a PIN,which you will get from the link displayed on screen.
Save the credential file for later use/sessions
save (cred, file="twitter authentication.Rdata")
load ("twitter authentication.Rdata") #to load in later session
Registering - should output TRUE if all is well
registerTwitterOAuth (cred)
Extracting Tweets
To get tweets from a particular user
userTimeline ('UserName',n=number of tweets,cainfo="cacert.pem")
To extract all tweets with a particular hashtag or user mention tweets <- searchTwitter (search.string, n=no.of.tweets, cainfo="cacert.pem", lang="en")




