1

According to the Rfigshare readme:,

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.

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.

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

My sessionInfo is as follows:

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

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.

(cross-posted from Github)

Otto Kässi
  • 2,943
  • 1
  • 10
  • 27

4 Answers4

3

The master branch of rfigshare seems to be out of sink with what figshare now offers in that the master branch seems to use v1 of the api along with oauth v1 authentication whereas figshare has moved on with v2 of the api and now promotes the use of oauth v2.

While I am unsure whether figshare has shutdown v1 of the api and/or has disallowed oauth v1, it seems like you might still be able to use the package if you install from the sckott branch and use a personal access token (PAT).

To generate a PAT, navigate to https://figshare.com/account/applications in a web browser. At the bottom of this page, you can generate a PAT. When the token is presented, copy it as you will not be able to view it again (although you can easily generate a new one at any time).

You will want to store this token in your .Renviron file. The usethis package has a nifty edit_r_environ() function to make this a little easier:

usethis::edit_r_environ()

Running the above in R should find your .Renviron file and open it for editing. Store your PAT on a new line.

RFIGSHARE_PAT="the-really-long-pat-you-should-have-on-your-clipbord"

Save and close the file. Make sure to restart your R session for this change to take effect.

You might then test to see if the above worked by running:

Sys.getenv("RFIGSHARE_PAT")

To see if your PAT is found.

Then install rfigshare from the sckott branch.

remotes::install_github("https://github.com/ropensci/rfigshare/tree/sckott")

Now you should be able to

library(rfigshare)
fs_browse()
the-mad-statter
  • 5,650
  • 1
  • 10
  • 20
  • Thanks! This seemed to work. I learned that `fs_upload()` was not working either. Sadly, Rfigshare seems antiquated for many tasks. – Otto Kässi Jun 11 '21 at 10:42
  • to avoid the restart, additionally run `Sys.setenv("RFIGSHARE_PAT"="ae4b1....")` – jan-glx Oct 11 '21 at 16:17
2

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)

the-mad-statter
  • 5,650
  • 1
  • 10
  • 20
  • Thank you for your help! This was clearly the way to go. I am still struggling with uploading files using `fs_api$operations$private_article_upload_initiate` and `fs_api$operations$private_article_upload_complete`; maybe that's for another question though. – Otto Kässi Jun 11 '21 at 09:45
1

I think one of the issues is that you're passing an article_id to fs_browse, which the first argument is not that. If you're looking to browse a public set, you can set mine = FALSE and session = NULL, like:

out = fs_details(article_id = 3761562, mine = FALSE, session = NULL)
John M
  • 1,115
  • 8
  • 10
  • Thanks, you are right. This does seem to work, but my workflow includes other tasks (fs_delete / fs_upload) in addition to listing contents of a repo, so this does not work for me. Alas. – Otto Kässi Jun 11 '21 at 10:39
0

Figshare support informed me that they have blocked requests done using http://. Switching the requests to https:// seemed to fix some of the issues on rfigshare. In particular, fs_details(), and fs_delete() works after switching to https://.

fs_upload() is broken even after switching to https.

Otto Kässi
  • 2,943
  • 1
  • 10
  • 27