-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ct_register_token()
does not validate token
#34
Comments
I believe I am having this exact issue: I have credentials for a premium account and thus a token, which I obtained from https://comtrade.un.org/api/swagger/ui/index#!/Auth/Auth_Authorize, and I have verified the validity of the token via https://comtrade.un.org/ws/CheckRights.aspx (which says that I have web service access using the token to the Comtrade database), but when I pass the token in R via |
Hi all, @wreesman, I'm not sure if these issues are necessarily related:
For now, I want to demonstrate issue (1): devtools::install_github("ropensci/comtradr")
library(comtradr) See what happens when we provide no token: # Check behaviour: no token
ct_register_token(NULL)
getOption("comtradr")
ct_get_remaining_hourly_queries()
So far, so good. Now, what if we add some random/invalid token instead? # Check behaviour: some random/invalid token
ct_register_token("badtoken")
ct_get_remaining_hourly_queries()
getOption("comtradr")
Here things go wrong. This is the initial issue #34 I reported. Potential solutionI just pushed a fix to branch token-validation. Now,
Start with a fresh R session and add your authentication token to R; mine is stored in variable require(remotes)
remotes::install_github("amannj/comtradr", ref = "token-validation") See what happens when we provide no token: # Check behaviour: no token
ct_register_token(NULL)
getOption("comtradr")
ct_get_remaining_hourly_queries()
Same as before. Now with a rubbish token: # Check behaviour: some random/invalid token
ct_register_token("badtoken")
ct_get_remaining_hourly_queries()
getOption("comtradr")
Good. Finally, let's try a legit one: ct_register_token(token = goodtoken)
getOption("comtradr")
ct_get_remaining_hourly_queries()
Looks good. The counter seems to be working as well: ex_1 <- ct_search(reporters = "China",
partners = c("Rep. of Korea", "USA", "Mexico"),
trade_direction = "exports")
ct_get_remaining_hourly_queries()
As I said before, I don't know if this also eliminates issue (2). For this, I think, we'd have to check if we still run into guest-user restrictions when sending out your queries. If we do, we should probably create a new issue. @ChrisMuir: In my fix, I also had to change |
@amannj, your potential solution worked on my end; the hourly queries command is now updating correctly when I pass my token. I have no insight into issue (2), however. If I run into hitches related to that as I am making my queries, I will let you know. |
Resolved in PR-37. |
Hi Chris,
I think
comtradr::ct_register_token()
fails to verify if the provided token is recognised by Comtrade's API:Maybe an easy way to check if a token is valid could be via getUserInfo. Maybe something like:
The text was updated successfully, but these errors were encountered: