rscopus package on R in MacBook - Invalid API key error

112 views Asked by At

I am trying to use the Scopus API for the first time. I have the API key and the institution token. However, I am still getting an error, when I try to use it in R on my Mac. Here is my code:

library(rscopus)

set_api_key(MY_KEY)
hdr=inst_token_header(MY_TOKEN)

key=get_api_key()
print(rscopus::get_api_key(), reveal=TRUE)
have_api_key()

auth_info = process_author_name(last_name="Muschelli", first_name="John", verbose=FALSE)

The error message is:

> library(rscopus)
> 
> set_api_key(MY_KEY)
> hdr=inst_token_header(MY_TOKEN)
> key=get_api_key()
> print(rscopus::get_api_key(), reveal=TRUE)
[1] "MY_KEY"
> have_api_key()
[1] TRUE
> 
> if (have_api_key()) {
+   auth = elsevier_authenticate(api_key=key)
+ }
HTTP specified is: https://api.elsevier.com/authenticate

Warning message:
In elsevier_authenticate(api_key = key) : Forbidden (HTTP 403).

> auth_info = process_author_name(last_name="Muschelli", first_name="John", verbose=FALSE)
$`service-error`
$`service-error`$status
$`service-error`$status$statusCode
[1] "AUTHENTICATION_ERROR"

$`service-error`$status$statusText
[1] "Invalid API Key: valid apikey credentials required."



Error in get_complete_author_info(...) : Service Error

I tried

if (have_api_key()) {
  auth = elsevier_authenticate(api_key=key)
}

but I get the error:

HTTP specified is: https://api.elsevier.com/authenticate

Warning message:
In elsevier_authenticate(api_key = key) : Forbidden (HTTP 403).

I have tried using auth_token_header(MY_TOKEN) instead of inst_token_header(MY_TOKEN) but the code is still not working.

I have also taken the following step in my terminal:

export Elsevier_API=MY_KEY > ~/.bash_profile source ~/.bash_profile

I am still getting the error. However, the combination of key and institution token work here: https://dev.elsevier.com/scopus.html

Can anyone please help me debug this issue?

Thank You!

1

There are 1 answers

0
Anisha Garg On

I figured out the issue. So, the correct way to query would be to pass the headers argument as well:

auth_info = process_author_name(last_name="Muschelli", first_name="John", verbose=FALSE, headers=hdr)

And now the code will work! :)