问题
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