Twitter app is not getting started

168 Views Asked by At

I have written following script to extract tweets from twitter.

library("twitteR")
library("ROAuth")
library("RCurl")
library("httr")
download.file(url="http://curl.haxx.se/ca/cacert.pem",destfile="cacert.pem")
ck <- '4QPOQJoiBgoGP7jU13Akxfp2E'
cs <- 'ued02VUpial3K8NW8foectZj1UFtsEfQetQJbYXD21uCj0ohJc'
ak <- '136316586-xWnCMrE5UYSzigTOwTVyR4NH4gfR01adpR5SF5IK'
as <- 'zsIj4lsDc5xKcDyofWkYijKnUY8Uj71sg1NfaIFKZbGc2'
reqURL<- 'https://api.twitter.com/oauth/request_token'
acURL <- 'https://api.twitter.com/oauth/access_token'
auURL <- 'https://api.twitter.com/oauth/authorize'
cred <- OAuthFactory$new(consumerKey=ck,consumerSecret=cs,requestURL=reqURL,accessURL=acURL,authURL=auURL)
cred$handshake(cainfo="cacert.pem")
save(cred, file="twitter_authentication.Rdata")
load("twitter_authentication.Rdata")
oauth_endpoints("twitter")
myapp <- oauth_app("twitter",key=ck,secret=cs)
twitter_token <- oauth1.0_token(oauth_endpoints("twitter"), myapp)
setup_twitter_oauth(ck,cs)
search.string <- "#Bahubali"
no.of.tweets <- 10
tweets <- searchTwitter(search.string, n=no.of.tweets, lang="en")
tweets
write.csv(tweets, file='/home/horopter/tweet/CSVTweets.csv', row.names=F)

However I get this setup_twitter_oauth(ck,cs) [1] "Using browser based authentication" Waiting for authentication in browser... Press Esc/Ctrl + C to abort

and I get stuck there. website either says 'You do not have permissions.' or doesn't open at all. If I don't give a callback url, it doesn't authenticate, otherwise gets stuck again as aforementioned. Help me out here.

1

There are 1 best solutions below

5
On BEST ANSWER

I used tried using the same code and authentication token and here is the code that worked for me. The setup_twitter_oauth requires all ck, cs, ak, as arguments.

library("twitteR")
library("ROAuth")
library("RCurl") 
library("httr")
download.file(url="http://curl.haxx.se/ca/cacert.pem",destfile="cacert.pem")
ck <- '4QPOQJoiBgoGP7jU13Akxfp2E'
cs <- 'ued02VUpial3K8NW8foectZj1UFtsEfQetQJbYXD21uCj0ohJc'
ak <- '136316586-xWnCMrE5UYSzigTOwTVyR4NH4gfR01adpR5SF5IK'
as <- 'zsIj4lsDc5xKcDyofWkYijKnUY8Uj71sg1NfaIFKZbGc2'
setup_twitter_oauth(ck,cs, ak, as)
search.string <- "#Bahubali"

This should setup your authentication once you have downloaded the .pem file. When it asks for authentication press 1.