Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Authorization for accessing BigQuery from R session on server

I am using R and package bigrquery to access Bigquery from an R session. This works great as long as 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 into my home directory on the server but this does not work. I get the error message:

Auto-refreshing stale OAuth token. Error in refresh_oauth2.0(self$endpoint, self$app, self$credentials) : client error: (400) Bad Request

I really have no idea about where to store the necessary credentials and unfortunately I was not able to find anything useful about that by google-searching the topic.

like image 324
malte Avatar asked Oct 16 '15 10:10

malte


People also ask

How do I access BigQuery with a service account?

Service Account based Authentication Click on Create. Now you should see an option to assign Service Account permissions. Under that you should find a drop down. Choose BigQuery-> BigQuery Admin.

How do I access Google BigQuery?

Find BigQuery in the left side menu of the Google Cloud Platform Console, under Big Data. Open your project in the console. If you're new to the console, you may need to sign up for a Google account, access the console, and create a project. Find BigQuery in the left side menu of the console, under Big Data.

What OAuth is used to represent permission?

The permissions represented by the access token, in OAuth terms, are known as scopes. When an application authenticates with Auth0, it specifies the scopes it wants. If those scopes are authorized by the user, then the access token will represent these authorized scopes.

How do I access BigQuery API?

https://bigquery.googleapis.com.


1 Answers

By default httr, which is used by bigrquery for oauth, will look in the R session's current working directory for .httr-oauth. You can override this location with the following (perhaps putting it in your .Rprofile if you like):

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

But for error message you received, its seems like the location is not the issue and it might be easier to just redo the oauth flow on the remote server to cache a new credential. To trigger a new oauth flow on the remote server:

  1. ensure the .httr-oauth file does not exist
  2. restart R
  3. perform one query with bigrquery

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

options(httr_oob_default = TRUE)
like image 140
Nicole Deflaux Avatar answered Oct 20 '22 15:10

Nicole Deflaux