How to authenticate in Google Big Query using Bigrquery without user input using a service account

生来就可爱ヽ(ⅴ<●) 提交于 2021-02-11 09:52:32

问题


I need to run an R script using windows task scheduler, however the script includes an authentication to Big Query using Bigrquery. I have the service account authentication. When I run the script I'm asked for user input which doesn't let me run the script as scheduled. I get:

The bigrquery package is requesting access to your Google account. 
Select a pre-authorised account or enter '0' to obtain a new token. Press 
Esc/Ctrl + C to abort

1. ("Account I've used to authenticate")

Here my code:

library(googleAuthR)
library(bigrquery)

scopes = c("https://www.googleapis.com/auth/bigquery")


options(googleAuthR.scopes.selected = scopes)
service_token <- gar_auth_service(json_file="somejason.json")
gar_auth_service("somejason.json")


projectid<-'project_id'
datasetid<-'id'
bq_conn <-  dbConnect(bigquery(), 
                      project = projectid,
                      dataset = datasetid, 
                      use_legacy_sql = FALSE
)

tables_list <- dbListTables(bq_conn)

The bigrquery package is requesting access to your Google account. Select 
a pre-authorised account or enter '0' to obtain a new token. Press 
Esc/Ctrl + C to abort.

1: ("Account I've used to authenticate")

Is there a way to authenticate with the service account without needing user input?


回答1:


So I read How to authenticate with service account and bigrquery package? .

There set_service_token(path='somejson.json') is suggested, but it's depricated. Instead, I used bq_auth(path='somejson.json').



来源:https://stackoverflow.com/questions/57059635/how-to-authenticate-in-google-big-query-using-bigrquery-without-user-input-using

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