geoffjentry / twitteR

R based twitter client
http://cran.r-project.org/web/packages/twitteR/index.html
254 stars 164 forks source link

[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 7 years ago

frnz347 commented 7 years ago

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 commented 7 years ago

I get the same error

jakeander commented 7 years ago

Same here.

lgheorma commented 7 years ago

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 commented 6 years ago

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 commented 6 years ago

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

nadeemkhan786 commented 6 years ago

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 commented 6 years ago

@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 commented 6 years ago

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

Bawage commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

Share your code please @mayankvik2

nadeemkhan786 commented 6 years ago

check working directory

ddten commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

Try changing the directory. Like say make a new folder in desktop and save it there and then write path C:/filename/desktop

On 21-Apr-2018, at 3:30 PM, jack-81 notifications@github.com<mailto:notifications@github.com> wrote:

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!

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/geoffjentry/twitteR/issues/137#issuecomment-383282516, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AkTNKiLiAb-2knTcbK5YbYgv2Cm_idPYks5tqwNQgaJpZM4LxENV.

jack-81 commented 6 years ago

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 commented 6 years ago

Hi there,

For solving error check the following: 1.you have also downloaded certificates in case using windows for interacting with twitter API..

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

  1. If direct auhrntication showing error then first perfotm handshaking with twitter API.

my_oauth <- OAuthFactory$new(consumerKey = consumerKey, consumerSecret = consumerSecret, requestURL = requestURL, accessURL = accessURL, authURL = authURL)

my_oauth$handshake(cainfo = system.file("CurlSSL", "cacert.pem", package = "RCurl"))

Thats all!! In case you still found show issue ,then comment again with complete code

On Sat, Apr 21, 2018 at 3:32 AM, ddten notifications@github.com wrote:

Try changing the directory. Like say make a new folder in desktop and save it there and then write path C:/filename/desktop

On 21-Apr-2018, at 3:30 PM, jack-81 <notifications@github.com<mailto: notifications@github.com>> wrote:

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!

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/ geoffjentry/twitteR/issues/137#issuecomment-383282516, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AkTNKiLiAb- 2knTcbK5YbYgv2Cm_idPYks5tqwNQgaJpZM4LxENV.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/geoffjentry/twitteR/issues/137#issuecomment-383284002, or mute the thread https://github.com/notifications/unsubscribe-auth/Akr05Uqd171gUaPdlZjdoBg5EefWMZpoks5tqwrOgaJpZM4LxENV .

monitotier commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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

jack-81 commented 6 years ago

Thanks for the solution. We have a new error!

Following your suggested steps, the following error was arised!

Error in function (type, msg, asError = TRUE) : Failed to connect to api.twitter.com port 443: Timed out

Win 7, R 3.4.4.

On Sun, Apr 22, 2018 at 4:52 AM, mayankvik2 notifications@github.com wrote:

Hi there,

For solving error check the following: 1.you have also downloaded certificates in case using windows for interacting with twitter API..

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

  1. If direct auhrntication showing error then first perfotm handshaking with twitter API.

my_oauth <- OAuthFactory$new(consumerKey = consumerKey, consumerSecret = consumerSecret, requestURL = requestURL, accessURL = accessURL, authURL = authURL)

my_oauth$handshake(cainfo = system.file("CurlSSL", "cacert.pem", package = "RCurl"))

Thats all!! In case you still found show issue ,then comment again with complete code

On Sat, Apr 21, 2018 at 3:32 AM, ddten notifications@github.com wrote:

Try changing the directory. Like say make a new folder in desktop and save it there and then write path C:/filename/desktop

On 21-Apr-2018, at 3:30 PM, jack-81 <notifications@github.com<mailto: notifications@github.com>> wrote:

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!

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/ geoffjentry/twitteR/issues/137#issuecomment-383282516, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AkTNKiLiAb- 2knTcbK5YbYgv2Cm_idPYks5tqwNQgaJpZM4LxENV.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/geoffjentry/twitteR/issues/ 137#issuecomment-383284002, or mute the thread https://github.com/notifications/unsubscribe-auth/ Akr05Uqd171gUaPdlZjdoBg5EefWMZpoks5tqwrOgaJpZM4LxENV

.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/geoffjentry/twitteR/issues/137#issuecomment-383343476, or mute the thread https://github.com/notifications/unsubscribe-auth/Aky7RpIXnoHdPJ1x-c8kyEdDdmAO7kS7ks5tq81egaJpZM4LxENV .

mad-moon commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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

PankajVerma123 commented 5 years ago

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 commented 5 years ago

Ya u must have good internet connection.

On Wednesday, November 28, 2018, PankajVerma123 notifications@github.com wrote:

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

}

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/geoffjentry/twitteR/issues/137#issuecomment-442389394, or mute the thread https://github.com/notifications/unsubscribe-auth/AjBubIo-p0uyLnVNCdgpbi7pP7J_95dBks5uzl7mgaJpZM4LxENV .

PankajVerma123 commented 5 years ago

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