Authorization for accessing BigQuery from R session on server

独自空忆成欢 提交于 2020-01-22 07:53:30

问题


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.


回答1:


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)


来源:https://stackoverflow.com/questions/33168363/authorization-for-accessing-bigquery-from-r-session-on-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!