通过 rfigshare 使用 Figshare API 时出现身份验证错误 [英] Authentication error when using Figshare API via rfigshare

查看:30
本文介绍了通过 rfigshare 使用 Figshare API 时出现身份验证错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据 Rfigshare 自述文件:

According to the Rfigshare readme:,

您第一次使用 rfigshare 功能时,它会要求您进行在线身份验证.只需登录并单击确定"即可对 rfigshare 进行身份验证.R 将允许您缓存您的登录凭据,这样您就不会被要求再次进行身份验证(即使在 R 会话之间),只要您将来使用相同的工作目录.

The first time you use an rfigshare function, it will ask you to authenticate online. Just log in and click okay to authenticate rfigshare. R will allow you to cache your login credentials so that you won't be asked to authenticate again (even between R sessions), as long as you are using the same working directory in future.

在新机器上安装 rfigshare 之后(没有现有的 .httr-oauth)

After installing rfigshare on a fresh machine (without an existing .httr-oauth)

library(devtools) 
install_github('ropensci/rfigshare')
library(rfigshare)

id = 3761562
fs_browse(id)

Error in value[[3L]](cond) : Requires authentication.
       Are your credentials stored in options?
       See fs_auth function for details.

因此,尽管自述文件说了些什么,但我不会被要求进行身份验证.

Thus, in spite of what the readme says, I am not asked to authenticate.

直接调用 fs_auth 也不起作用:

Directly calling fs_auth does not work either:

> fs_auth()
Error in init_oauth1.0(self$endpoint, self$app, permission = self$params$permission,  :
  Bad Request (HTTP 400).

我的sessionInfo如下:

My sessionInfo is as follows:

sessionInfo()

sessionInfo()

R version 4.0.5 (2021-03-31)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Big Sur 10.16

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRblas.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib

locale:
[1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] rfigshare_0.3.7.100

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.6       magrittr_2.0.1   tidyselect_1.1.0 munsell_0.5.0
 [5] colorspace_2.0-1 R6_2.5.0         rlang_0.4.11     fansi_0.5.0
 [9] httr_1.4.2       dplyr_1.0.5      grid_4.0.5       gtable_0.3.0
[13] utf8_1.2.1       DBI_1.1.1        ellipsis_0.3.2   assertthat_0.2.1
[17] yaml_2.2.1       tibble_3.1.2     lifecycle_1.0.0  crayon_1.4.1
[21] RJSONIO_1.3-1.4  purrr_0.3.4      ggplot2_3.3.3    later_1.2.0
[25] vctrs_0.3.8      promises_1.2.0.1 glue_1.4.2       compiler_4.0.5
[29] pillar_1.6.1     generics_0.1.0   scales_1.1.1     XML_3.99-0.6
[33] httpuv_1.6.1     pkgconfig_2.0.3

有人有任何提示或解决方法吗?这肯定在 6 个月前我上次尝试时确实有效.我也有一个关于 Figshare 支持的关于这个问题的开放线程,但他们对 R 库的了解似乎有限.

Does anyone have any tips or workarounds? This definitely did work maybe 6 months ago when I last tried. I also have an open thread about this issue with Figshare support, but their knowledge of the R library seems limited.

(交叉发布自 Github)

推荐答案

您还可以考虑利用当前的 figshare api 与 Open API 兼容这一事实,并使用 swagger 规范即时构建您自己的客户端.

You might also consider leveraging the fact that the current figshare api is Open API compatible and build your own client on the fly with the swagger specification.

如我在其他答案中所述,生成并存储个人访问令牌.那你就可以了

Generate and store a personal access token as I described in my other answer. Then you could do

library(rapiclient)
library(httr)

fs_api <- get_api("https://docs.figshare.com/swagger.json")
header <- c(Authorization = sprintf("token %s", Sys.getenv("RFIGSHARE_PAT")))
fs_api <- list(operations = get_operations(fs_api, header), 
               schemas = get_schemas(fs_api))

my_articles <- fs_api$operations$private_articles_list()
content(my_articles)

这篇关于通过 rfigshare 使用 Figshare API 时出现身份验证错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆