Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ROAuth no longer used in favor of httr? [Twitter API]

I'm running R Studio on an AWS "Ubuntu Server 12.04.2 LTS" and accessing R Studio via my browser.

When I try to authenticate at the Twitter API using the package ROAuth with the code:

credential<-OAuthFactory$new(consumerKey="xxxxx",
                             consumerSecret="xxxxx",
                             requestURL="https://api.twitter.com/oauth/request_token",
                             accessURL="https://api.twitter.com/oauth/access_token",
                             authURL="https://api.twitter.com/oauth/authorize")

credential$handshake()
registerTwitterOAuth(credential)

I get an error after registerTwitterOAuth(credential) saying

  Error in registerTwitterOAuth(credential) : 
  ROAuth is no longer used in favor of httr, please see ?setup_twitter_oauth

However I can't find any further explanation..

like image 909
SPi Avatar asked Aug 28 '13 19:08

SPi


3 Answers

Apparently the twitteR package was changed right before I posted this, so the new way to authenticate is

setup_twitter_oauth(CUSTOMER_KEY, CUSTOMER_SECRET, ACCESS_TOKEN, ACCESS_secret, credentials_file=NULL)

see https://github.com/geoffjentry/twitteR

like image 153
SPi Avatar answered Oct 13 '22 02:10

SPi


I had some issues with setup_twitter_oauth() function. I ran the following code and it worked for me without any error.

library(RCurl)
require(twitteR)
library(ROAuth)
reqURL <- "https://api.twitter.com/oauth/request_token"
accessURL <- "https://api.twitter.com/oauth/access_token"
authURL <- "https://api.twitter.com/oauth/authorize"
api_Key <-  "XXXXXXX"
api_Secret <- "XXXXXXXXXXXXXXXXX"

twitCred <- OAuthFactory$new(consumerKey=api_key,
                            consumerSecret=api_secret,
                            requestURL=reqURL,
                            accessURL=accessURL,
                            authURL=authURL
)
twitCred$handshake()

EDIT:

Just now sorted the issues I had with my app's access_token, now setup_twitter_oauth function is working perfectly.

Try the below code for Twitter authentication with R, if your api_key, api_secret, acsess_token, access_token_secret are generated without errors.

api_key = "XXXXXXXXX" // your api_key
api_secret = "XXXXXXXXXX" // your api_secret 
access_token = "XXXXXXXXXX" // your access_token 
access_token_secret = "XXXXXXXXXX" // your access_token_sceret 
setup_twitter_oauth(api_key,api_secret,access_token,
                     access_token_secret)
like image 28
Deepak selva Avatar answered Oct 13 '22 02:10

Deepak selva


The following worked for me:

packages <- c("twitteR","ROAuth")#"openssl","base64enc"
### checking if packages are already installed and installing if not
check.install.load.Package<-function(package_name){
  if(!package_name%in%installed.packages()){
    install.packages(package_name)
  }
  library(package_name,character.only = TRUE)
}
for(package in packages){
  check.install.load.Package(package)
}


api_key = "XX" # your api_key
api_secret = "XX" # your api_secret 
access_token = "XX" # your access_token 
access_token_secret = "XX" # your access_token_sceret 
credential<-OAuthFactory$new(consumerKey=api_key,
                             consumerSecret=api_secret,
                             requestURL="https://api.twitter.com/oauth/request_token",
                             accessURL="https://api.twitter.com/oauth/access_token",
                             authURL="https://api.twitter.com/oauth/authorize")

credential$handshake()

setup_twitter_oauth(api_key,api_secret,access_token,
                    access_token_secret)



search.string <- "#RohingyaTerrorReality"
no.of.tweets <- 60

RohingyaTerrorReality.Tweets <- searchTwitter(search.string, n=no.of.tweets,lang="en",)



df <- do.call("rbind", lapply(RohingyaTerrorReality.Tweets, as.data.frame))
View(df)
like image 28
served_raw Avatar answered Oct 13 '22 00:10

served_raw