skip to Main Content

I am not able to create a twitter token using create_token from rtweet package:

library (rtweet)
twitter_token <- create_token(app = appname, # as set in Twitter API
                              consumer_key = key, # as set in Twitter API
                              consumer_secret = secret) # as set in Twitter API

The output I get is:

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

I followed the instructions to setup Twitter API as disclosed in http://rtweet.info/articles/auth.html, and triple checked that the Callback URL was properly set as http://127.0.0.1:1410.

I also tried:

createTokenNoBrowser<- function(appName, consumerKey, consumerSecret, 
                                accessToken, accessTokenSecret) {
  app <- httr::oauth_app(appName, consumerKey, consumerSecret)
  params <- list(as_header = TRUE)
  credentials <- list(oauth_token = accessToken, 
                      oauth_token_secret = accessTokenSecret)
  token <- httr::Token1.0$new(endpoint = NULL, params = params, 
                              app = app, credentials = credentials)
  return(token)
}

It seems to work, but when I call

rt <- stream_tweets(q = q, file_name = filename,token = twitter_token)

I get: Error: Not a valid access token.

What might be going wrong?
I am currently using R 3.5.0. Thank you.

> sessionInfo()
R version 3.5.0 (2018-04-23)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

Matrix products: default

locale:
[1] LC_COLLATE=Portuguese_Brazil.1252  LC_CTYPE=Portuguese_Brazil.1252    LC_MONETARY=Portuguese_Brazil.1252
[4] LC_NUMERIC=C                       LC_TIME=Portuguese_Brazil.1252    

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] readr_1.1.1     httr_1.3.1      compiler_3.5.0  magrittr_1.5    R6_2.2.2        hms_0.4.2       tools_3.5.0     pillar_1.2.3   
 [9] curl_3.2        tibble_1.4.2    yaml_2.1.19     Rcpp_0.12.17    jsonlite_1.5    openssl_1.0.1   pkgconfig_2.0.1 rlang_0.2.1  

2

Answers


  1. I believe create_token() is deprecated in the latest version of rtweet. Instead, you should use rtweet_app() or rtweet_bot().

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search