Skip to content
This repository has been archived by the owner on Apr 11, 2019. It is now read-only.

[1] "Using direct authentication" Error in check_twitter_oauth() : OAuth authentication error: This most likely means that you have incorrectly called setup_twitter_oauth()' #137

Open
frnz347 opened this issue Jan 30, 2017 · 29 comments

Comments

@frnz347
Copy link

frnz347 commented Jan 30, 2017

Hello Guys,

When I try to establish establish a connection to the Twitter API, I get an error:

setup_twitter_oauth(API_key, API_secret, access_token, access_secret)
[1] "Using direct authentication"
Error in check_twitter_oauth() : OAuth authentication error:
This most likely means that you have incorrectly called setup_twitter_oauth()'

Please guide me on this. I have tried all the solutions offered in here, nothing worked for me.

The following is my R sessionInfo:

R version 3.3.2 (2016-10-31)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

locale:
[1] LC_COLLATE=English_Australia.1252 LC_CTYPE=English_Australia.1252
[3] LC_MONETARY=English_Australia.1252 LC_NUMERIC=C
[5] LC_TIME=English_Australia.1252

attached base packages:
[1] stats graphics grDevices utils datasets methods base

loaded via a namespace (and not attached):
[1] tools_3.3.2

Thanks,

Farnaz

@mikkelkrogsholm
Copy link

I get the same error

@jakeander
Copy link

Same here.

@lgheorma
Copy link

lgheorma commented Feb 27, 2017

I've tried the following: adding the old version of the httr package, turning my firewall off, adding the base64enc package and nothing worked... And yes, I have installed all the packages AND I used the library function before trying to use them.
I don't know what else to do. I have Windows 8.1 and the most up to date versions of R, R studio, and of the packages.

Here is my code

library("base64enc")
library("twitteR")
library("ROAuth")
library("devtools")
library("memoise")
library("whisker")
library("rstudioapi")
library("git2r")
library("withr")
library("rjson")
library("bit64")
library ("httr")
library ("httpuv")

download.file(url="http://curl.haxx.se/ca/cacert.pem",destfile="cacert.pem")
consumerKey <- "key"
consumerSecret <- "key"
accessToken <- "key"
accessTokenSecret <- "key"

setup_twitter_oauth(consumerKey, consumerSecret, accessToken, accessTokenSecret)

*key= for each line I added the corresponding key from my Twitter App page.

@gallard28
Copy link

I had this problem when I went to scrape tweets. I solved it by opening libraries for "httpuv" and "openssl".

Session Info:
R version 3.4.1 (2017-06-30)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS High Sierra 10.13.2

Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats graphics grDevices utils datasets
[6] methods base

other attached packages:
[1] dplyr_0.7.4 stringr_1.2.0 tm_0.7-3
[4] NLP_0.1-11 wordcloud_2.5 RColorBrewer_1.1-2
[7] SnowballC_0.5.1 httpuv_1.3.5 openssl_0.9.9
[10] twitteR_1.1.9

loaded via a namespace (and not attached):
[1] Rcpp_0.12.14 bindr_0.1 xml2_1.1.1
[4] magrittr_1.5 bit_1.1-12 lattice_0.20-35
[7] rjson_0.2.15 R6_2.2.2 rlang_0.1.6
[10] httr_1.3.1 tools_3.4.1 parallel_3.4.1
[13] grid_3.4.1 DBI_0.7 assertthat_0.2.0
[16] yaml_2.1.14 bit64_0.9-7 tibble_1.3.4
[19] bindrcpp_0.2 Matrix_1.2-12 curl_2.8.1
[22] glue_1.2.0 slam_0.1-42 stringi_1.1.5
[25] compiler_3.4.1 pkgconfig_2.0.1

Code below:

#Load Libraries
library("twitteR")
library("openssl")
library("httpuv")

library("twitteR")
library("tm")
library("stringr")
library("dplyr")

#Save your Twitter account Keys and Tokens. If you do not have a twitter account. https://apps.twitter.com/

consumer_key<-"code"
consumer_secret<-"code"
access_token <- "code"
access_secret <- "code"

#Connects you to Twitter
setup_twitter_oauth(consumer_key, consumer_secret, access_token , access_secret)
origop <- options("httr_oauth_cache")
options(httr_oauth_cache = TRUE)

#ChancellorDav Tweets
CD_Timeline <- userTimeline(user = "ChancellorDav", n = 3200, includeRts = FALSE, excludeReplies = TRUE)
toSpace <- content_transformer(function (x , pattern ) gsub(pattern, " ", x))

#Sapply Approach
CD_tweets <- sapply(CD_Timeline, function(x) { strsplit(gsub("[^[:alnum:] ]", "", x$text), " +")[[1]] })

#Overview of Data Scraped
head(CD_tweets)
tail(CD_tweets)
str(CD_tweets)

@dhelly
Copy link

dhelly commented Mar 20, 2018

This library resolve my problem.
library("openssl")
library("httpuv")

@nadeemkhan786
Copy link

nadeemkhan786 commented Mar 27, 2018

when i run code OTP get generated but when i use "search" command error can be generated

library(twitteR)
library(ROAuth)
#ibrary("openssl")
#ibrary("httpuv")
#library(base64enc)
consumer_key <- "code"
consumer_secret <- "code"
access_token <- "code"
access_secret <- "code"

#setup_twitter_oauth(consumer_key,consumer_secret,access_token,access_secret)

download.file(url="http://curl.haxx.se/ca/cacert.pem",destfile="cacert.pem")

setup_twitter_oauth(consumer_key,consumer_secret,access_token,access_secret)

tcred <- OAuthFactory$new(consumerKey=consumer_key,
consumerSecret=consumer_secret,
requestURL='https://api.twitter.com/oauth/request_token',
accessURL='https://api.twitter.com/oauth/access_token',
authURL='https://api.twitter.com/oauth/authorize')

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

Error in twInterfaceObj$doAPICall(cmd, params, "GET", ...) :
OAuth authentication error:
This most likely means that you have incorrectly called setup_twitter_oauth()'

version 3.4.3 please help me

@BroVic
Copy link

BroVic commented Mar 27, 2018

@nadeemkhan786 I get this error when I have poor internet. But you could fix the typos in your code so we're certain that we're on the same page....

@nadeemkhan786
Copy link

nadeemkhan786 commented Mar 28, 2018

@BroVic but i have good internet still i am in same place (error)

@Bawage
Copy link

Bawage commented Mar 30, 2018

I am getting following error. Can anybody guide me?

Error in twInterfaceObj$doAPICall(cmd, params, "GET", ...) :
OAuth authentication error:
This most likely means that you have incorrectly called setup_twitter_oauth()'

@luizot
Copy link

luizot commented Apr 3, 2018

Please, how to correct this error?

library(twitteR)
library(ROAuth)
library(RCurl) Carregando pacotes exigidos: bitops
library(openssl)
library(httpuv)
library(base64enc)
library(httr)
options(httr_oauth_cache=T)
setup_twitter_oauth(consumer_key,consumer_secret,access_token,access_secret)
[1] "Using direct authentication"
Error in check_twitter_oauth() : OAuth authentication error:
This most likely means that you have incorrectly called setup_twitter_oauth()'

@ddten
Copy link

ddten commented Apr 4, 2018

I wrote a code like this and got an error as below:
library(httr)
options(httr_oauth_cache=T)
library(devtools)
library(twitteR)
library(base64enc)
library(ROAuth)
library(plyr)
library(dplyr)
library(stringr)
library(RCurl)
library(httpuv)
library(openssl)
library(ggplot2)
consumer_key<-"code"
consumer_secret<-"code"
access_token<-"code"
access_secret<-"code"
setup_twitter_oauth(consumer_key,consumer_secret,access_token,access_secret)
[1] "Using direct authentication"
Error in check_twitter_oauth() : OAuth authentication error:
This most likely means that you have incorrectly called setup_twitter_oauth()'
Can somebody help?

@mayankvik2
Copy link

mayankvik2 commented Apr 19, 2018

Thanks a lot. Using library openssl and httpuv resolved my Error in check_twitter_oauth() : OAuth authentication error. I was getting worried and in the end of two days I read this post and nailed the error out of my program. Once again thanks!!!

@ddten
Copy link

ddten commented Apr 19, 2018

Share your code please @mayankvik2

@nadeemkhan786
Copy link

check working directory

@ddten
Copy link

ddten commented Apr 19, 2018

library("twitteR")
library("openssl")
library("httpuv")
library("twitteR")
library("tm")
library("stringr")
library("dplyr")

api_key <- " code"
api_secret <- "code"
access_token <- "code"
access_secret <- "code"

setup_twitter_oauth(api_key,api_secret,access_token,access_secret)
origop <- options("httr_oauth_cache")
options(httr_oauth_cache = TRUE)
I saved my code in desktop and set it as working directory but still the errors of check twitter oauth came.

@jack-81
Copy link

jack-81 commented Apr 21, 2018

Tried all the posted solutions but still face the same error:
[1] "Using direct authentication"
Error in check_twitter_oauth() : OAuth authentication error:
This most likely means that you have incorrectly called setup_twitter_oauth()'

Please anyone help to resolve this weird problem. I'm trying for a week to solve this and checked almost all the related forums around the Web. Here is my last place to ask or I will uninstall R and start another language!

@ddten
Copy link

ddten commented Apr 21, 2018 via email

@jack-81
Copy link

jack-81 commented Apr 21, 2018

I think this is an important issue that has many solutions. Do you think setting a bounty on bountify can be helpful.

I really need to solve this for an important project.

@mayankvik2
Copy link

mayankvik2 commented Apr 22, 2018 via email

@monitotier
Copy link

I exactly have the same issue, I have tried everything! it is so frustrating, Let me know if you solve it and how did you do it. I am still working on it too.

@ddten
Copy link

ddten commented Apr 25, 2018

Have you both @monitotier @mayankvik2 tried to set the working directory? Like if you make a new folder on desktop named say R Studio then set the working directory as that?
Also regenerate all the keys.
Try writing the code like I did
library("openssl")
library("httpuv")
library("twitteR")
library("tm")
library("stringr")
library("dplyr")

api_key <- " code"
api_secret <- "code"
access_token <- "code"
access_secret <- "code"

setup_twitter_oauth(api_key,api_secret,access_token,access_secret)
origop <- options("httr_oauth_cache")
options(httr_oauth_cache = TRUE)
Also if you have problems with twitteR you can use rtweet.

@monitotier
Copy link

@ddten: Thanks for your quick response. After going through more threads I found that this package was missing "base64enc". It helped!
Thanks 😃

@jack-81
Copy link

jack-81 commented Apr 27, 2018 via email

@mad-moon
Copy link

I found the solution in a Stackoverflow post. try to run setup_twitter_oauth(consumer_key, consumer_secret) and see what libraries are missing then install them.

@akinsbola452000
Copy link

Thanks guys. I got same issue resolved by following the instructions on this forum. I simply added all the required library and followed the advice from @ddten to regenerate the all the keys. Now i'm working perfectly.

@GeekSnuff
Copy link

Thanks akinsbola452000
I wasn't regenerating the keys!
phew...

@PankajVerma123
Copy link

during handshake with twitter i get error :-
Error in setup_twitter_oauth(consumer_key = consumerKey, consumer_secret = consumerSecret, :
could not find function "setup_twitter_oauth. please suggest me solution to this issue.
this is my rstudio code and i am using R 3.5.1

setting working directory

library(twitteR)
library(ROAuth)
library(plyr)
library(dplyr)
library(stringr)
library(ggplot2)
library(httr)
library(wordcloud)
library(SentimentAnalysis)
library(sentimentr)
library(RCurl)
library(openssl)
library(httpuv)
library(base64enc)
library(devtools)

oauth_endpoint(authorize = "https://api.twitter.com/oauth",
access = "https://api.twitter.com/oauth/access_token")

#connect to API
download.file(url ='http://curl.haxx.se/ca/cacert.pem', destfile ='cacert.pem')
reqURL <- 'https://api.twitter.com/oauth/request_token'
accessURL <- 'https://api.twitter.com/oauth/access_token'
authURL <- 'https://api.twitter.com/oauth/authorize'

Twitter Application

consumerKey="3GcJah1mIIDPD6c4uIW08L8YU"
consumerSecret="uevNdolvKfdCcG779UpiiD2wHTmP86kAUMqH7I9cjRuA3iJ35r"
accesstoken="869394410-vZb0G5EjJVF9STyLvVDotknPchwhcZ63zftWYyJe"
accesssecret="Ea3kWs4UCTqdNrWA76Wzall5MV2xRorrwlE8DYsc4ul5w"

cred <- OAuthFactory$new(consumerKey=consumerKey,
consumerSecret=consumerSecret,
requestURL=reqURL,
accessURL=accessURL,
authURL=authURL)
cred$handshake(cainfo = system.file('CurlSSL', 'cacert.pem', package = 'RCurl'))

There is URL in console. You need to go to it, get code and enter it on console

Authorization PIN ~DYNAMIC

save(cred, file='twitter authentication.Rdata')

load('twitter authentication.Rdata')

Once you launch the code first time, you can start from this in the future(libraries should be connected)

setup_twitter_oauth(consumer_key = consumerKey,consumer_secret = consumerSecret,
access_token = accesstoken,access_secret = accesssecret)

###*******Step 3: Performs tweets extraction and data cleaning

Harvest some tweets

some_tweets = searchTwitter("statue of unity", n=5000, since = "2017-01-01", lang="en")

some_tweets = searchTwitter("Sardar Vallab Bhai Patel",n=5000, since = "2017-01-01", lang = "en")

(n.some_tweets <- length(some_tweets))

some_tweets.df <- ldply(some_tweets, function(t) t$toDataFrame())
write.csv(some_tweets.df,"tweets.csv")

get the text

some_txt = sapply(some_tweets, function(x) x$getText())

#remove request entities
some_txt = gsub("(RT/via)((?:\b\w*@\w+)+)","", some_txt)
#remove at people
some_txt = gsub("@\w+", "", some_txt)
#remove punctuation
some_txt = gsub("[[:punct:]]", "", some_txt)
#remove numbers
some_txt = gsub("[[:digit:]]","", some_txt)

remove html links

some_txt = gsub("http\w+","", some_txt)

remove unnecessary spaces

some_txt = gsub("[\t]{2,}","", some_txt)
some_txt = gsub("^\s+|\s+$","", some_txt)

define "tolower error handling" function

try.error = function(x)
{
#creating missing values
y = NA
#try catch error
try_error = tryCatch(tolower(x), error=function(e) e)

if not an error

if (!inherits(try_error, "error"))
y = tolower(x)

result

return(y)
}

#Tower case using try.error with sapply
some_txt = sapply(some_txt, try.error)

remove NAS in some_txt

some_txt = some_txt[!is.na(some_txt)]
names(some_txt) = NULL

}

@nadeemkhan786
Copy link

nadeemkhan786 commented Nov 28, 2018 via email

@PankajVerma123
Copy link

anyone please help me find the issue with my code . i didn't get solution to this problem till yet, so please help me or send me r code to extract tweet that will be working in R 3.5.1.

  • i found this problem many time with different code
    Error in setup_twitter_oauth(consumer_key = consumerKey, consumer_secret = consumerSecret, :
    could not find function "setup_twitter_oauth. please suggest me solution to this issue.
    this is my rstudio code and i am using R 3.5.1

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests