Skip to content
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

Unauthorized (HTTP 401). Failed to get an access token. #45

Closed
analytics-ml opened this issue Jan 9, 2018 · 16 comments
Closed

Unauthorized (HTTP 401). Failed to get an access token. #45

analytics-ml opened this issue Jan 9, 2018 · 16 comments

Comments

@analytics-ml
Copy link

I encounter the following error while authentication with Google. (bqr_auth() )

Error in oauth2.0_access_token(endpoint, app, code = code, user_params = user_params, :
Unauthorized (HTTP 401). Failed to get an access token.
In addition: Warning message:
In googleAuthR::gar_auto_auth(required_scopes, new_user = new_user, :
travis_environment_var argument is now unsupported and does nothing

it was working perfectly before updating the package to version 0.3.2.

Other libraries like bigrquery authenticate perfectly but not bigQueryR.

Where is the problem any suggestions?

@MarkEdmondson1234
Copy link
Collaborator

Could you report your sessionInfo() ? I suspect it’s you need to update to googleAuthR 0.6.2. If that’s installed please try reauthenticate with a fresh session.

@analytics-ml
Copy link
Author

analytics-ml commented Jan 9, 2018

googleAutR is 0.6.2. Also tried older version. Prompt error "require googleAuthR version >= 0.6.2"

sessioninfo()
R version 3.4.2 (2017-09-28)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Sierra 10.12.6

Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRlapack.dylib

locale:
[1] C

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] googleCloudStorageR_0.4.0 googleAuthR_0.6.2 lubridate_1.7.1
[4] bigQueryR_0.3.2

loaded via a namespace (and not attached):
[1] Rcpp_0.12.14 digest_0.6.13 assertthat_0.2.0 R6_2.2.2
[5] jsonlite_1.5 magrittr_1.5 zip_1.0.0 httr_1.3.1
[9] stringi_1.1.6 curl_3.1 tools_3.4.2 stringr_1.2.0
[13] yaml_2.1.16 compiler_3.4.2 memoise_1.1.0 openssl_0.9.9

Also tried and delete the .httr-oauth file and create a new separate file. Both didn't work either.

@MarkEdmondson1234
Copy link
Collaborator

May I ask for the code you are using to authenticate? Are you using your own client ID/secret?

@MarkEdmondson1234
Copy link
Collaborator

Ok I could replicate it.

Short term I suggest you authenticate via the service JSON method, which involves downloading the auth.json and then placing it in the environment argument BQ_AUTH_FILE - this authentication is functioning normally. There are some details here: http://code.markedmondson.me/googleAuthR/articles/google-authentication-types.html#authentication-with-a-json-file-via-service-accounts

Long term I will fix this, which is caused by the scopes changing during authentication when using the bq_auth() function.

@MarkEdmondson1234
Copy link
Collaborator

MarkEdmondson1234 commented Jan 9, 2018

I think this is due to my default bigQueryR project becoming unverified e.g. it works if you set your own client ID and secret via googleAuthR::gar_set_client() and similar.

@analytics-ml
Copy link
Author

analytics-ml commented Jan 10, 2018

i was using bqr_auth() to authenticate
Want to upload dataset to bigquery.
job<-bqr_upload_data(projectId = "xyz",
datasetId = "test_dataset",
tableId="test_table",
upload_data = df
)

@peteratemarsys
Copy link
Contributor

Had the same issue and posted it on stackOverflow. Only after that did I find this thread. Posted an answer with a link pointing here. You might want to post there too if a fix is in place.

@analytics-ml
Copy link
Author

analytics-ml commented Jan 10, 2018

Thank you for suggesting JSON method. It worked.
I also want to mention that wait = FALSE argument in bqr_upload_data() doesn't return and waits for the job to complete. (it wait till the entire dataset is uploaded.)
where am I doing wrong?

I want to upload a dataset of around 1 Million rows and 39 columns to big query daily(without using google cloud. Or cloud is the only option?).

@MarkEdmondson1234
Copy link
Collaborator

Cool, I think the answer here for now is to configure using your own Google Cloud project, since the bigQueryR doesn't work at the moment. I'll answer your follow up question in another issue to keep this one clean.

@MarkEdmondson1234
Copy link
Collaborator

MarkEdmondson1234 commented Jan 10, 2018

@analytics-ml see #47

@MarkEdmondson1234
Copy link
Collaborator

Related? r-dbi/bigrquery#182

MarkEdmondson1234 added a commit that referenced this issue Jan 12, 2018
@MarkEdmondson1234
Copy link
Collaborator

@analytics-ml @peteratemarsys the original bigQueryR Google project has been verified now, so I think it should work again as before using the CRAN version? Can anyone confirm? In any case, the GitHub version works for me using the bigQueryR Google project.

@peteratemarsys
Copy link
Contributor

@MarkEdmondson1234 It still doesn't work with the CRAN version. I uninstalled and then re-installed the package to make sure and got the same error message. I then tried too with the GitHub version and that works just fine.

@peteratemarsys
Copy link
Contributor

Hi @MarkEdmondson1234 ! Do you plan to pick this up again? I tried it using the CRAN version again and can confirm that using email authentication doesn't work. I'm asking because in our project we would sometimes need to use service key authentication (e.g. running services on a server) but sometimes it'd be more convenient to use the email authentication for personal analysis.

@MarkEdmondson1234
Copy link
Collaborator

Hi @peteratemarsys are you saying it works with the GitHub version? In that case I will just make sure to publish that to CRAN ASAP

@peteratemarsys
Copy link
Contributor

Hi @MarkEdmondson1234! Yes, it works with the GitHub version. Many thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants