0

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!

Anisha Garg
  • 53
  • 5
  • 10
  • So do you have a key or do you have a token? If you have a key, don't call the `inst_token_header` function. Those seem to me mutually exclusive login methods. What line exactly gives the error you've shown. Please show the output of these commands so it's not clear what they are returning. Feel free to edit out parts of the API key but at least show some output. Also check out the info at https://github.com/muschellij2/rscopus. Note that keys are associated with IPs address. Are you using the same IP address for your code that you did when creating the key? – MrFlick Jan 31 '23 at 14:50
  • 1. If I use inst_token_header, it asks me for a key. And if I use the API key only, I get the same error. 2. Yes, I use the same IP address that I used for generating the key. 3. All other commands are running the standard output. I will update the above query to include what they are returning. – Anisha Garg Jan 31 '23 at 15:32

1 Answers1

0

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! :)

Anisha Garg
  • 53
  • 5
  • 10