rtweet icon indicating copy to clipboard operation
rtweet copied to clipboard

Authentication problems

Open todaatsushi opened this issue 8 years ago • 5 comments

Hi all,

Getting the common authentication issue. Error in init_oauth1.0(self$endpoint, self$app, permission = self$params$permission, : Unauthorized (HTTP 401).

After going through the old posts, I'm at a loss. Here are the common fixes (that I've found) and tried:

  • Callback URL (set to http://127.0.0.1:1410)
  • Blank spaces/bad characters in copy and pasted key (manually typed in)
  • Reinstalling the latest version (both CRAN and GitHub)

The setup_twitter_oauth function in the twitteR package seems to work fine.

Here is the code used:

devtools::install_github("mkearney/rtweet") library(rtweet)

appname <- "RTTtracker" key <- "xxxx" secret <- "xxxx"

twitter_token <- create_token(app = appname, consumer_key = key, consumer_secret = secret)

Any and all help will be appreciated. Thanks for all the hard work!

todaatsushi avatar May 16 '18 15:05 todaatsushi

I'm having a hard to replicating this issue. Can you try explicitly including the token in a search_tweets() call (like the code below). Does this work? If you get an error, can you paste the output (error message)?

## create token
twitter_token <- create_token(app = appname, 
   consumer_key = key, consumer_secret = secret) 

## search tweets with explicit token arg
search_tweets("lang:en", token = twitter_token)

Regardless of whether the above code works, can you paste the output from the following as well?

## print TWITTER_PAT environment variable
Sys.getenv("TWITTER_PAT")

## print token fetched by `get_token()` function
get_token()

## print session info
sessionInfo()

mkearney avatar May 16 '18 16:05 mkearney

Thanks for the quick response, here are your outputs:

## create token
twitter_token <- create_token(app = appname, 
   consumer_key = key, consumer_secret = secret) 

Returns: Error in init_oauth1.0(self$endpoint, self$app, permission = self$params$permission, : Unauthorized (HTTP 401).

## search tweets with explicit token arg
search_tweets("lang:en", token = twitter_token)

Returns: Error in search_tweets("lang:en", token = twitter_token) : object 'twitter_token' not found

Pasted Outputs:

## print TWITTER_PAT environment variable
Sys.getenv("TWITTER_PAT")

Returns: [1] ""

## print token fetched by `get_token()` function
get_token()

Returns:

Error: API user token required. see http://rtweet.info/articles/auth.html for instructions
## print session info
sessionInfo()

Returns:

R version 3.4.3 (2017-11-30)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: macOS Sierra 10.12.6

Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libLAPACK.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  methods   base     

other attached packages:
[1] rtweet_0.6.4

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.16    digest_0.6.15   withr_2.1.2     R6_2.2.2       
 [5] jsonlite_1.5    git2r_0.21.0    magrittr_1.5    pillar_1.2.1   
 [9] httr_1.3.1      rlang_0.2.0     curl_3.2        devtools_1.13.5
[13] tools_3.4.3     readr_1.1.1     hms_0.4.2       yaml_2.1.18    
[17] compiler_3.4.3  pkgconfig_2.0.1 memoise_1.1.0   openssl_1.0.1  
[21] knitr_1.20      tibble_1.4.2   

Hope this is insightful.

I was thinking that it could only be me somehow filling in the details wrong of the app like the name but I've done it so many times and pretty carefully so I'm not sure at all.

Thanks in advance.

todaatsushi avatar May 16 '18 16:05 todaatsushi

@broadsinatlanta have you unchecked 'Enable Callback Locking' in your Twitter App settings?

nzstefinitely avatar May 17 '18 03:05 nzstefinitely

I was having the same problem until I unchecked 'Enable Callback Locking'. Now works.

MHenderson avatar May 17 '18 13:05 MHenderson

Yup, worked perfectly. Thanks everyone!

todaatsushi avatar May 17 '18 13:05 todaatsushi