numbats / achievement-scraper

Other
1 stars 0 forks source link

`rorcid` authentication #13

Closed MikeLydeamore closed 2 weeks ago

MikeLydeamore commented 4 weeks ago

It seems we need a Public API key to access rorcid works. See here: https://orcid.org/developer-tools

I have got mine working by:

  1. Setting up an application:

    image
  2. Setting up this script:

    
    library(httr)
    orcid_client_id <- FILL_IN

orcid_client_secret <- FILL_IN

orcid_request <- POST(url = "https://orcid.org/oauth/token", config = add_headers(Accept = "application/json", Content-Type = "application/x-www-form-urlencoded"), body = list(grant_type = "client_credentials", scope = "/read-public", client_id = orcid_client_id, client_secret = orcid_client_secret), encode = "form")

orcid_response <- content(orcid_request) print(orcid_response$access_token)


Take the output of that, and run

Sys.setenv("ORCID_TOKEN"=orcid_response$access_token)



You'll need to run this in each session.

If you restart your R session after doing this, I seem to be able to grab other people's public records.
parnikakhattri commented 2 weeks ago

Hi Michael,

I have successfully set up the .Renviron file using usethis::edit_r_environ(), and it shows the expected output for the ORCID_TOKEN. When I run the script to check the environment variable, it correctly displays the token:

orcid_token <- Sys.getenv("ORCID_TOKEN") print(orcid_token) [1] ""

However, I encounter an Error: Unauthorized (HTTP 401) when attempting to fetch data using the rorcid package. This suggests an issue with the authentication process, despite the token appearing correctly in my script.

Could you please advise on how to resolve this authorisation issue?

MikeLydeamore commented 2 weeks ago

The empty string means that you don't have a token set. What is the contents of the .Renviron file? Make sure you take out the actual token that's in there, just replace it with a placeholder.

Michael

parnikakhattri commented 2 weeks ago

I apologise for the confusion; the string is not empty. I omitted the value for security purposes. However, everything is working now after I reloaded the package.