无法使用rtweet包创建令牌

时间:2018-06-06 21:22:37

标签: r rtweet

我无法使用rtweet package中的create_token创建Twitter令牌:

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

我得到的输出是:

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

我按照http://rtweet.info/articles/auth.html中的说明按照说明设置了Twitter API,并三次检查回调网址是否已正确设置为http://127.0.0.1:1410

我也尝试过:

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)
}

似乎有效,但是当我打电话时

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

我得到:Error: Not a valid access token.

可能出现什么问题? 我目前正在使用R 3.5.0。谢谢。

> 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  

1 个答案:

答案 0 :(得分:2)