Closed MikeLydeamore closed 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?
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
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.
It seems we need a Public API key to access
rorcid
works. See here: https://orcid.org/developer-toolsI have got mine working by:
Setting up an application:
Setting up this script:
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)
Sys.setenv("ORCID_TOKEN"=orcid_response$access_token)