WHAT YOU NEED
httr package- forhttp requests and authentication
NOTE: this post has been updated with the latest twitteR package from github.The latest version simplifies the procedure and has favoured httr package over ROAuth
TO INSTALL FROM GITHUB
library(devtools)
install_github(“geoffjentry/twitteR”)
TO CREATE APP IN TWITTER
Goto Manage Apps in the bottom
Create App
TO ACCESS TWEETS THROUGH twitteR
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
setup_twitter_oauth(“ConsumerKey”, ConsumerSecret”,
“AccessKey”,
“AccessToken”)
EXTRACT TWEETS
To get tweets from a particular user
userTimeline(‘UserName’,n=number of tweets)
To extract all tweets with a particular hashtag or user mention
tweets <- searchTwitter(search.string, n=no.of.tweets, lang=”en”)
TO ACCESS TWEETS THROUGH REST API
#library(httr)
get OAuth endpoints for twitter
end=oauth_endpoints(“twitter”)
Create a signed token
app=oauth_app(“twitter”,app_id,app_secret)
token=sign_oauth1.0(app,access_token,access_secret
Extract tweets another user’s Timeline
Number of tweets that can be extracted from timeline is restricted to 3,200 tweets.Also,one page can yield of maximum of 200 tweets(count),so to extract the maximum tweets will require multiple calls,with different page_no
res=GET(url="https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=screen_name&count=count&page=page_no",config=(token=token))