Authorize access to BigQuery from an R session on the server

I am using R and the bigrquery package to access Bigquery from an R session. This works fine while I am on my local machine. However, when I try to access Bigquery from R on a remote server, it does not work at all.

I tried to copy the .httr-oauth file to my home directory on the server, but this will not work. I get an error message:

Auto-renew obsolete OAuth token. Error in refresh_oauth2.0 (self $ endpoint, self $ app, self $ credentials): client error: (400) Invalid request

I really have no idea where to store the necessary credentials, and, unfortunately, I could not find anything useful in this matter using google-search for the topic.

+5
source share
1 answer

By default, httr, which is used by bigrquery for oauth, will look in the current R session working directory for .httr-oauth. You can redefine this location as follows (maybe put it in your .Rprofile if you want):

options("httr_oauth_cache"="~/.httr-oauth") 

But for the error message you received, it seems that this place is not a problem, and it would be easier to just redo the oauth stream on the remote server to cache the new credentials. To initiate a new oauth stream on a remote server:

  • ensure that the .httr-oauth file does not exist
  • restart R
  • execute one query using bigrquery

Note that if httr tries to redirect to localhost, you can force it to execute an out-of-band oauth stream with:

 options(httr_oob_default = TRUE) 
+8
source

Source: https://habr.com/ru/post/1233857/


All Articles