16

I was following the vignette for the package, updated and loaded all necessary packages, seemed like it would be a pretty straight-forward process to authenticate. Instead, I get an error

> 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()'

My paraphrased and redacted program looks more-or-less like this.

library("twitteR")
download.file(url="http://curl.haxx.se/ca/cacert.pem", destfile="cacert.pem") #read this was necessary for Windows machines
consumer_key <- 'abc'
consumer_secret <- 'abc'
access_token <- '123-abc'
access_secret <- 'abc'
setup_twitter_oauth(consumer_key, consumer_secret, access_token, access_secret)

I read a lot of the other SO questions on this topic, nothing solved my issue (most of them used the old authentication process anyway). I'm trying to create a wordcloud following this tutorial.

Tyler Beason
  • 193
  • 1
  • 2
  • 9
  • 1
    This used to work just fine for me, but I just opened my script and received the same error. Are you running R 3.2.1? – Molx Jun 30 '15 at 03:06
  • 1
    Actually, it seems that the problem is caused by an update to the httr package. An [issue](https://github.com/geoffjentry/twitteR/issues/90) has already been created on TwitteR github repo, with a workaround. – Molx Jun 30 '15 at 03:10
  • @Molx thanks for the info! the workaround worked perfectly and I have successfully authenticated using the program above – Tyler Beason Jun 30 '15 at 03:25

11 Answers11

21

Just (install and) load the package 'base64enc'.

Funkwecker
  • 766
  • 13
  • 22
3

I had to do the following settings to make this work

package versions : base64enc_0.1-3 httr_1.2.1 twitteR_1.1.8

installed twitteR using command: devtools::install_github("jrowen/twitteR", ref = "oauth_httr_1_0")

And i had an existing app which didnt work so i went ahead a created a new app on twitter.

This combination works for me

3

Just check your firewall settings and allow R through.

I tried all the the different solutions mentioned regarding packages , etc. None of them worked. I finally found that it is nothing but a simple firewall issue. I recommend that everybody who faces this issue first check their firewall settings. Make sure that R is added in the list of applications allowed through the firewall. This should solve the issue.

2

install.packages("base64enc") was what solved this issue for me.

jcel
  • 29
  • 4
2

I tried all the suggestions here but surprisingly none worked for me. Somebody could be going through the same situation as I did so I answer with what worked for me- it seems that the problem was with direct authentication, so I followed the following steps(this requires one to have the openssl package) installed and loaded along with the twitteR package;

Ensure you have created your twitter API and have the consumerkey and consumerSecret codes, and preferably remain logged into twitter with your default web browser

packages <- c("twitteR", "openssl")
### checking if packages are already installed and installing if not
for(i in packages){
    if(!(i %in% installed.packages()[, "Package"])){
        install.packages(i)
    }
library(i, character.only = TRUE) ## load packages
}

setup_twitter_oauth(consumer_key, consumer_secret) ## do not input the access_token and access_secret

This is going to open up your default browser with the successful authentication message. You can close the browser now and continue exploring tweets with R.

John Mutuma
  • 3,150
  • 2
  • 18
  • 31
1

I encountered the same problems, and after so many attempts.

I found this issue https://github.com/geoffjentry/twitteR/issues/90, where 'jrowen' suggested a work-around that solved my problem. The issue apparently is caused by the new httr package, but the work-around is to install the twitteR package from GitHub instead of the cran repository using this command:

devtools::install_github("jrowen/twitteR", ref = "oauth_httr_1_0")

After this, the problem of OAuth authentication error disappeared. Hope this also works for you.

Lachezar
  • 6,523
  • 3
  • 33
  • 34
API
  • 480
  • 3
  • 10
  • @AmitKohli Could you be more specific? What message/output did you see when you tried the one I listed above? And what did you encounter before you tried it? – API Aug 21 '15 at 15:48
  • I get the same error: `Error in check_twitter_oauth() : OAuth authentication error: This most likely means that you have incorrectly called setup_twitter_oauth()'`. Does it make a difference how I answer this question?:`"Using direct authentication" Use a local file to cache OAuth access credentials between R sessions`? – Amit Kohli Aug 24 '15 at 13:30
  • @Alex_Feng I finally solved the problem by reinstalling latest dev version of `TwitteR`, latest cran version of `httr`, and latest cran version of `base64enc`. Cheers. – Amit Kohli Aug 26 '15 at 09:56
  • @AmitKohli thanks for sharing. I think what you did was consistent with what I did. I updated all other packages via cran, and then installed the dev version of TwitteR by the code I listed above (and here as well): `devtools::install_github("jrowen/twitteR", ref = "oauth_httr_1_0")` – API Sep 09 '15 at 05:03
1

Try to regenerate the consumer key and access_token keys. I also faced the similar problem. Nothing resolved my problem. But after I regenerated the keys and used the new keys its resolved and works beauty.

0

I used a different wireless network (which was less secure) and this worked for me

frank
  • 3,036
  • 7
  • 33
  • 65
0

Adding proxy fix my issue hope this would have some others issue fixed

provided you already have a proxy, then input the following line:

proxy_url <- "http://127.0.0.1:61387/"
Sys.setenv(http_proxy = proxy_url, https_proxy = proxy_url, ftp_proxy = proxy_url)

note:change the settings to your own

cloudscomputes
  • 1,278
  • 13
  • 19
0

Faced the same problem. Then realized that I was not logged into Twitter (from default browser). Logged in to Twitter and everything worked perfectly.

Ratul
  • 401
  • 4
  • 5
-1

The problem for me was that my curl was out-of-date, so it wasn't able to verify the SSL certificate it was receiving. All I had to do is update curl (simply conda update curl if you're using anaconda) and oauth worked perfectly after that.

Ashish Tyagi
  • 807
  • 6
  • 5