Skip to content
This repository has been archived by the owner on Nov 10, 2024. It is now read-only.

Error in init_oauth1.0(self$endpoint, self$app, permission = self$params$permission, : Forbidden (HTTP 403). #251

Closed
StupidLaptop opened this issue Jun 13, 2018 · 30 comments

Comments

@StupidLaptop
Copy link

StupidLaptop commented Jun 13, 2018

Problem

Hi there,

Have been trying to create a token, at first had the 401 issue for not having set up the callback URL. Now after setting it I'm getting this error.

Error in init_oauth1.0(self$endpoint, self$app, permission = self$params$permission, : Forbidden (HTTP 403).

In another thread I saw that apparently unticking the "Enable Callback Locking" should get rid of the error but that hasn't worked either. Just wondering if this is a new bug or if I'm doing something wrong.

This is my code:
`library(rtweet)
appname <- "rTweetFetcha"
key <- "%KEY%"
secret <- "%SECRET%"
twitter_token <- create_token(app = appname, consumer_key = key, consumer_secret = secret)

project_directory <- path.expand(getwd())
file_name <- file.path(project_directory, "twitter_token.rds")
twitter_token
saveRDS(twitter_token, file = file_name)
cat(paste0("TWITTER_PAT=", file_name),
file = file.path(project_directory, ".Renviron"),
append = TRUE)`

@Frank5547
Copy link

Frank5547 commented Jun 13, 2018

I am getting the same error after unticking "Enable Callback Locking." My code is as follows:

library(rtweet)
library(httpuv)

create_token(app = "TweeterCatcher",
consumer_key = "Token",
consumer_secret = "Secret")

UsersLocal <- search_tweets("#localization", n = 2000,
include_rts = FALSE)
##########
As a minor update. If this issue persists, you can use TweetR setup_twitter_oauth like this and use TweetR's functions. Make sure to specify access_token and access_secret in addition to the other two.

token2 <- setup_twitter_oauth(consumer_key = "x",consumer_secret = "y", access_token="z",
access_secret="n")

@omhs
Copy link

omhs commented Jun 13, 2018

I am also getting the same error. First, it was just unticking "Enable Callback Locking." I am working with the same code lines. Out of blue i received "Error in init_oauth1.0(self$endpoint, self$app, permission = self$params$permission, : Forbidden (HTTP 403)". To be precise, since 00:01 Tuesday night (morning of the 13th).

After trying a lot and too much i guess i now also receive additional error,

"$<-.data.frame(*tmp*, "app", value = "rtweet_token") :
replacement has 1 row, data has 0"

"Error: 32 - Could not authenticate you".

@mkearney
Copy link
Collaborator

make sure you have the most recent github version

devtools::install_github("mkearney/rtweet")

@StupidLaptop You don't need to save the token and token/path. create_token() will do that for you.

Otherwise these issues should be resolved by providing the correct keys and making sure app configuration is correct. You might also try generating new keys and then retry creating a new token using those.

@Frank5547
Copy link

@mkearney I tried your suggestions, but they had no effect. I get the same HTTP error 403. I made sure that all the settings in my twitter app are as they are supposed to be per your instructions (I have attached a screenshot for reference).

Could it be that the Twitter API now requires the access token and secret? I find strange that twitteR setup_twitter_oauth() works perfectly fine when I add them in addition to the consumer secret and key while create_token(), which worked perfectly until today fails.

image

@mkearney
Copy link
Collaborator

Hrmm, well they haven't changed your ability to create a token that way.

What version of rtweet?

## copy/paste output
packageVersion("rtweet")

What about R version/ other session info?

## copy/paste output
sessionInfo()

And your keys look more like the example below than the word "Token" right? (just making sure)

Does the error always happen when you run create_token()? If not you can store it as a token object and try a search with explicitly referencing the token.

token <- create_token(app = "TweeterCatcher",
  consumer_key = "XYznzPFOFZR2a39FwWKN1Jp41",
  consumer_secret = "CtkGEWmSevZqJuKl6HHrBxbCybxI1xGLqrD5ynPd9jG0SoHZbD")

search_tweets("lang:en", token = token)

@omhs
Copy link

omhs commented Jun 14, 2018

Still have also the same problems. Trying all the settings of your instructions, too. Refreshing tokens, installing newest rtweet version, creating a new app, and also the last code. But it always produces an error and cannot run create_token().

packageVersion("rtweet")
[1] ‘0.6.5’

R version 3.5.0 (2018-04-23)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS High Sierra 10.13.4

@ColinFay
Copy link

Got the same here :

#remotes::install_github("mkearney/rtweet")
packageVersion("rtweet")
#> [1] '0.6.5'
rtweet::create_token(
  app = "DataColinFAYR",
  consumer_key = "***",
  consumer_secret = "***")
#> Error in init_oauth1.0(self$endpoint, self$app, permission = self$params$permission, : Forbidden (HTTP 403).
Session info
devtools::session_info()
#> Session info -------------------------------------------------------------
#>  setting  value                       
#>  version  R version 3.4.4 (2018-03-15)
#>  system   x86_64, darwin15.6.0        
#>  ui       X11                         
#>  language (EN)                        
#>  collate  fr_FR.UTF-8                 
#>  tz       Europe/Paris                
#>  date     2018-06-14
#> Packages -----------------------------------------------------------------
#>  package   * version    date       source                          
#>  backports   1.1.2      2017-12-13 CRAN (R 3.4.3)                  
#>  base      * 3.4.4      2018-03-15 local                           
#>  compiler    3.4.4      2018-03-15 local                           
#>  curl        3.2        2018-03-28 CRAN (R 3.4.4)                  
#>  datasets  * 3.4.4      2018-03-15 local                           
#>  devtools    1.13.5     2018-02-18 CRAN (R 3.4.3)                  
#>  digest      0.6.15     2018-01-28 CRAN (R 3.4.3)                  
#>  evaluate    0.10.1     2017-06-24 CRAN (R 3.4.1)                  
#>  graphics  * 3.4.4      2018-03-15 local                           
#>  grDevices * 3.4.4      2018-03-15 local                           
#>  hms         0.4.2      2018-03-10 CRAN (R 3.4.4)                  
#>  htmltools   0.3.6      2017-04-28 CRAN (R 3.4.0)                  
#>  httr        1.3.1      2017-08-20 CRAN (R 3.4.1)                  
#>  jsonlite    1.5        2017-06-01 CRAN (R 3.4.0)                  
#>  knitr       1.20       2018-02-20 CRAN (R 3.4.3)                  
#>  magrittr    1.5        2014-11-22 CRAN (R 3.4.0)                  
#>  memoise     1.1.0      2017-04-21 CRAN (R 3.4.0)                  
#>  methods   * 3.4.4      2018-03-15 local                           
#>  openssl     1.0.1      2018-03-03 CRAN (R 3.4.3)                  
#>  pkgconfig   2.0.1      2017-03-21 CRAN (R 3.4.0)                  
#>  R6          2.2.2.9000 2018-06-06 Github (r-lib/R6@a9eb0f1)       
#>  Rcpp        0.12.17    2018-05-18 CRAN (R 3.4.4)                  
#>  rlang       0.2.1      2018-05-30 CRAN (R 3.4.4)                  
#>  rmarkdown   1.10       2018-06-11 CRAN (R 3.4.4)                  
#>  rprojroot   1.3-2      2018-01-03 CRAN (R 3.4.3)                  
#>  rtweet      0.6.5      2018-06-14 Github (mkearney/rtweet@8b9ba15)
#>  stats     * 3.4.4      2018-03-15 local                           
#>  stringi     1.2.2      2018-05-02 CRAN (R 3.4.4)                  
#>  stringr     1.3.1      2018-05-10 CRAN (R 3.4.4)                  
#>  tools       3.4.4      2018-03-15 local                           
#>  utils     * 3.4.4      2018-03-15 local                           
#>  withr       2.1.2      2018-06-01 Github (jimhester/withr@70d6321)
#>  yaml        2.1.19     2018-05-01 CRAN (R 3.4.4)

@ColinFay
Copy link

Here is with the token you provided just before :

packageVersion("rtweet")
#> [1] '0.6.5'
library(rtweet)
token <- create_token(app = "TweeterCatcher",
                      consumer_key = "XYznzPFOFZR2a39FwWKN1Jp41",
                      consumer_secret = "CtkGEWmSevZqJuKl6HHrBxbCybxI1xGLqrD5ynPd9jG0SoHZbD")
#> Error in init_oauth1.0(self$endpoint, self$app, permission = self$params$permission, : Unauthorized (HTTP 401).
Session info
devtools::session_info()
#> Session info -------------------------------------------------------------
#>  setting  value                       
#>  version  R version 3.4.4 (2018-03-15)
#>  system   x86_64, darwin15.6.0        
#>  ui       X11                         
#>  language (EN)                        
#>  collate  fr_FR.UTF-8                 
#>  tz       Europe/Paris                
#>  date     2018-06-14
#> Packages -----------------------------------------------------------------
#>  package   * version    date       source                          
#>  backports   1.1.2      2017-12-13 CRAN (R 3.4.3)                  
#>  base      * 3.4.4      2018-03-15 local                           
#>  compiler    3.4.4      2018-03-15 local                           
#>  curl        3.2        2018-03-28 CRAN (R 3.4.4)                  
#>  datasets  * 3.4.4      2018-03-15 local                           
#>  devtools    1.13.5     2018-02-18 CRAN (R 3.4.3)                  
#>  digest      0.6.15     2018-01-28 CRAN (R 3.4.3)                  
#>  evaluate    0.10.1     2017-06-24 CRAN (R 3.4.1)                  
#>  graphics  * 3.4.4      2018-03-15 local                           
#>  grDevices * 3.4.4      2018-03-15 local                           
#>  hms         0.4.2      2018-03-10 CRAN (R 3.4.4)                  
#>  htmltools   0.3.6      2017-04-28 CRAN (R 3.4.0)                  
#>  httr        1.3.1      2017-08-20 CRAN (R 3.4.1)                  
#>  jsonlite    1.5        2017-06-01 CRAN (R 3.4.0)                  
#>  knitr       1.20       2018-02-20 CRAN (R 3.4.3)                  
#>  magrittr    1.5        2014-11-22 CRAN (R 3.4.0)                  
#>  memoise     1.1.0      2017-04-21 CRAN (R 3.4.0)                  
#>  methods   * 3.4.4      2018-03-15 local                           
#>  openssl     1.0.1      2018-03-03 CRAN (R 3.4.3)                  
#>  pkgconfig   2.0.1      2017-03-21 CRAN (R 3.4.0)                  
#>  R6          2.2.2.9000 2018-06-06 Github (r-lib/R6@a9eb0f1)       
#>  Rcpp        0.12.17    2018-05-18 CRAN (R 3.4.4)                  
#>  rlang       0.2.1      2018-05-30 CRAN (R 3.4.4)                  
#>  rmarkdown   1.10       2018-06-11 CRAN (R 3.4.4)                  
#>  rprojroot   1.3-2      2018-01-03 CRAN (R 3.4.3)                  
#>  rtweet    * 0.6.5      2018-06-14 Github (mkearney/rtweet@8b9ba15)
#>  stats     * 3.4.4      2018-03-15 local                           
#>  stringi     1.2.2      2018-05-02 CRAN (R 3.4.4)                  
#>  stringr     1.3.1      2018-05-10 CRAN (R 3.4.4)                  
#>  tools       3.4.4      2018-03-15 local                           
#>  utils     * 3.4.4      2018-03-15 local                           
#>  withr       2.1.2      2018-06-01 Github (jimhester/withr@70d6321)
#>  yaml        2.1.19     2018-05-01 CRAN (R 3.4.4)

@ColinFay
Copy link

@hupseb this is not an rtweet issue, but an httr issue :

library(httr)
token <- oauth_app(appname = "TweeterCatcher", key = gsub(" ", "", "XYznzPFOFZR2a39FwWKN1Jp41"), 
                   secret = gsub(" ", "", "CtkGEWmSevZqJuKl6HHrBxbCybxI1xGLqrD5ynPd9jG0SoHZbD"))
connected <- oauth1.0_token(oauth_endpoints("twitter"), token, 
                        cache = FALSE)
#> Error in init_oauth1.0(self$endpoint, self$app, permission = self$params$permission, : Unauthorized (HTTP 401).
Token1.0$new(
  app = token, 
  endpoint = oauth_endpoints("twitter"), 
  cache = FALSE
)
#> Error in init_oauth1.0(self$endpoint, self$app, permission = self$params$permission, : Unauthorized (HTTP 401).
Session info
devtools::session_info()
#> Session info -------------------------------------------------------------
#>  setting  value                       
#>  version  R version 3.4.4 (2018-03-15)
#>  system   x86_64, darwin15.6.0        
#>  ui       X11                         
#>  language (EN)                        
#>  collate  fr_FR.UTF-8                 
#>  tz       Europe/Paris                
#>  date     2018-06-14
#> Packages -----------------------------------------------------------------
#>  package   * version    date       source                          
#>  backports   1.1.2      2017-12-13 CRAN (R 3.4.3)                  
#>  base      * 3.4.4      2018-03-15 local                           
#>  compiler    3.4.4      2018-03-15 local                           
#>  curl        3.2        2018-03-28 CRAN (R 3.4.4)                  
#>  datasets  * 3.4.4      2018-03-15 local                           
#>  devtools    1.13.5     2018-02-18 CRAN (R 3.4.3)                  
#>  digest      0.6.15     2018-01-28 CRAN (R 3.4.3)                  
#>  evaluate    0.10.1     2017-06-24 CRAN (R 3.4.1)                  
#>  graphics  * 3.4.4      2018-03-15 local                           
#>  grDevices * 3.4.4      2018-03-15 local                           
#>  htmltools   0.3.6      2017-04-28 CRAN (R 3.4.0)                  
#>  httr      * 1.3.1      2017-08-20 CRAN (R 3.4.1)                  
#>  knitr       1.20       2018-02-20 CRAN (R 3.4.3)                  
#>  magrittr    1.5        2014-11-22 CRAN (R 3.4.0)                  
#>  memoise     1.1.0      2017-04-21 CRAN (R 3.4.0)                  
#>  methods   * 3.4.4      2018-03-15 local                           
#>  openssl     1.0.1      2018-03-03 CRAN (R 3.4.3)                  
#>  R6          2.2.2.9000 2018-06-06 Github (r-lib/R6@a9eb0f1)       
#>  Rcpp        0.12.17    2018-05-18 CRAN (R 3.4.4)                  
#>  rmarkdown   1.10       2018-06-11 CRAN (R 3.4.4)                  
#>  rprojroot   1.3-2      2018-01-03 CRAN (R 3.4.3)                  
#>  stats     * 3.4.4      2018-03-15 local                           
#>  stringi     1.2.2      2018-05-02 CRAN (R 3.4.4)                  
#>  stringr     1.3.1      2018-05-10 CRAN (R 3.4.4)                  
#>  tools       3.4.4      2018-03-15 local                           
#>  utils     * 3.4.4      2018-03-15 local                           
#>  withr       2.1.2      2018-06-01 Github (jimhester/withr@70d6321)
#>  yaml        2.1.19     2018-05-01 CRAN (R 3.4.4)

@hupseb
Copy link

hupseb commented Jun 14, 2018

This is the reason: https://twitter.com/TwitterAPI/status/1006635008692350977

As announced last month, today marks the beginning of callback URL whitelisting enforcement. Apps using Sign in with Twitter who have not whitelisted their URLs will experience disruption. To whitelist your URLs, follow the guidance in our May forum post.

@hupseb
Copy link

hupseb commented Jun 14, 2018

So to summarize the solution: The callback_url is already provided. What worked for me was providing access_token and access_secret.

create_token(app=...,consumer_key=..., consumer_secret=..., access_token=..., access_secret=...)

@StupidLaptop
Copy link
Author

That worked for me, after installing the latest github version as suggested by @mkearney . Thanks to everyone!

@omhs
Copy link

omhs commented Jun 14, 2018

Same for me. Newest version of r, rstudio as well as rtweet. Now all works fine again. Thank you for fast solution @hupseb.

@mkearney
Copy link
Collaborator

Thanks @hupseb for the link!

I suppose I should switch documentation over to the full signature method (provide all four keys to create a token), but I'm still puzzled and annoyed that the browser handshake is not working. Twitter claims the Enable Callback Locking option should disappear on June 12th. It's June 14th and it still hasn't (and it still allows me to have that box be unchecked)...and yet users are getting errors as though callback locking is hardwired in. I still think users should be able to sign their tokens via web browser, but it appears the instructions provided by the httr package are no longer valid. Perhaps there is something I can do internally to generate the authorization URL/manage the callback options.

@mkearney
Copy link
Collaborator

mkearney commented Jun 14, 2018

Anyway, I'm really sorry for the hassle, everyone! I've spent the last month inundated with messages about token creation errors due to these changes by Twitter, and I haven't been able to replicate the errors myself due to being wary of getting disciplined again from Twitter for having multiple tokens* and maybe due to my account being opaquely grandfathering in or something. (*Having to share my personal token with the test token in rtweet makes troubleshooting oauth issues especially annoying for me).

Thank you all for being patient and reporting your errors!

@mkearney
Copy link
Collaborator

@StupidLaptop @Frank5547 @omhs @hupseb @ColinFay

Good news!

I believe I've fixed this problem: mkearney@eb9b400

Please let me know if you try it and it works [or doesn't]!

@ghost
Copy link

ghost commented Jun 14, 2018

With the latest dev version, the browser opens and it says I am authenticated, but I get this error in R immediately following the "authentication complete" message:

Error in verifier$oauth_verifier %||% verifier[[1]] :
could not find function "%||%"

Thanks for your hard work on this! <3

@mkearney
Copy link
Collaborator

i just fixed that :)

@ghost
Copy link

ghost commented Jun 14, 2018

!

Okay, and now: "Error: Not a valid access token."
(when I try to interact with the API)

You are the best!

@mkearney
Copy link
Collaborator

Had to dig in a little more to export everything I needed out of the httr pkg but I think it should be good to go now!

@omhs
Copy link

omhs commented Jun 14, 2018

For me it is working nice again. Without any extra token anymore plus now finally registration of the App. Cause exactly what you mentioned, the buttons should be away if you take Twitter by word, but they aren't. Read several times it will be gone after 12th. But anyway.

Thank You a lot @mkearney for taking care so fast. That saves my phd work :D

@josephquinn
Copy link

I'm having the same issue - it looks like the devtools version of the package won't install because I get the following error:

ERROR: dependency 'openssl' is not available for package 'rtweet'

  • removing 'C:/Users/jmq4/Documents/R/win-library/3.4/rtweet'
    Installation failed: Command failed (1)

Any thoughts?

@mkearney
Copy link
Collaborator

Give it another try now. I just moved the openssl dep to 'suggests' instead of 'imports.'

@martynscn
Copy link

Thanks. re-installing rtweets from github fixed the error

@drf5n
Copy link

drf5n commented Jun 22, 2018

On the https://github.com/mkearney/rtweet#api-authorization page, the create_token() function no longer seems to accept the 2b arguments acess_token or access_secret.

@drf5n
Copy link

drf5n commented Jun 22, 2018

I don't see the callback lock button in twitter, and I'm getting the error:

> create_token(   app = "rtweet_drf5n",   consumer_key = "key",   consumer_secret = "secret")
Error in init_oauth1.0(self$endpoint, self$app, permission = self$params$permission,  : 
  Forbidden (HTTP 403).
> 

@humbertohpgit
Copy link

Installing form here: devtools::install_github("mkearney/rtweet") and setting the callback url to http://127.0.0.1:1410 finally worked for me.
Thanks for the pointers!

@jennykathambi90
Copy link

https://github.com/mkearney/rtweet/issues/265#issuecomment-464338166

There was a change by Twitter on June 12th. To fix this problem you need to use 4 keys/secrets/tokens.

create_token(
app = appname,
consumer_key = key,
consumer_secret = secret,
access_token = access_token,
access_secret = access_secret
)

@amunozab
Copy link

I had the same issue: "Error in init_oauth1.0(self$endpoint, self$app, permission = self$params$permission, : Forbidden (HTTP 403)"
and I could fix it by reinstalling the latest version of "rtweet".

@daniel-hain
Copy link

I have the same issue. For some reason

`token <- create_token(
app = appname,
consumer_key = key,
consumer_secret = secret,
access_token = key_acess,
access_secret = key_secret)

rstats_tweets <- search_tweets(q = "#rstats", n = 500)
`
Leads to:
Warning: 32 - Could not authenticate you.
Warning message:
Could not authenticate you.

Use the latest devtools::install_github("mkearney/rtweet") version.

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

No branches or pull requests