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

5

8

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..

Spatterdash answered 28/8, 2013 at 19:13 Comment(0)
S
6

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

Spatterdash answered 28/8, 2013 at 20:17 Comment(0)
D
1

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)
Draghound answered 3/11, 2015 at 10:11 Comment(0)
E
1

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)
Ebullient answered 13/9, 2017 at 20:10 Comment(0)
C
1

Here is the R script that worked for me:

 library("twitteR")
 library("ROAuth")

download.file(url= "http://curl.haxx.se/ca/cacert.pem", destfile= "cacert.pem")
credentials <- OAuthFactory$new(consumerKey='XXXXXXXXXXXXXXXXXX',
  consumerSecret='XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
  requestURL='https://api.twitter.com/oauth/request_token',
  accessURL='https://api.twitter.com/oauth/access_token',
  authURL='https://api.twitter.com/oauth/authorize')

credentials$handshake(cainfo="cacert.pem")

save(credentials, file="twitter authentication.Rdata")

load("twitter authentication.Rdata")

setup_twitter_oauth(credentials$consumerKey, credentials$consumerSecret, 
credentials$oauthKey, credentials$oauthSecret)
Collate answered 27/10, 2018 at 1:40 Comment(0)
A
0

I´m having some issues using the setup_twitter_oauth function. I run the following code and don´t get an object after the setup_twitter_oauth function is run or the credentials file loaded.

Then i just load the cred_1.RData file and i get a sig objetc that doesn´t seem to be useful.

I´m on windows and installed the github version of the package.

rm(list = ls(,all=T))


setwd("D:\\TWEETS\\cuenta_1")
library(twitteR)
library(httr)

# Credenciales

consumer_key =   "xxxxxxxxxxxxxxxx"
consumer_secret = "xxxxxxxxxxxxxxxx"
access_token = "xxxxxxxxxxxxxxxxxxx"
access_secret = "xxxxxxxxxxxxxxxx"

credentials_file = "cred_1.RData"

setup_twitter_oauth(consumer_key, consumer_secret, access_token, access_secret, credentials_file)
load_twitter_oauth("cred_1.RData")

ls()

> ls()
[1] "access_secret"    "access_token"     "consumer_key"     "consumer_secret" 
[5] "credentials_file"


> load("cred_1.RData")
> 
> ls()
[1] "access_secret"      "access_token"       "consumer_key"       "consumer_secret"    "credentials_file"   "load_twitter_oauth" "set_oauth_sig"     
[8] "sig"               
> 
> print(sig)
Config: 
List of 1
 $ signature:function (method, url)  
Authority answered 4/11, 2013 at 21:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.