Search code examples
rgoogle-bigquery

Unable to authenticate to bigrquery without browser using service account


I'm trying to setup a service account in my R script. This is what I have so far

library(bigrquery)
library(DBI)

json_path <- "json_path.json"

bq_auth(path = json_path)

And this gives me

bq_auth(path = json_path)

Waiting for authentication in browser...

Press Esc/Ctrl + C to abort VSCode WebView only supports showing local

http content. Opening in external browser...

I've read everyone say that this is all they need to do in order to get their service account working, but I cannot get it to work. When I do this it forces me to try and authenticate via browser. There are multiple SO posts, a medium post, and the bigrquery reference that all shows this is supposed to be all I need to do in order to setup the service account.

This isn't working for me so there must be something else. What else do I need to do in order to setup the service account


Solution

  • library(bigrquery)
    library(DBI)
    json_path <- "path_to_your_service_account_key.json"
    # Set environment variable for service account JSON
    Sys.setenv(GOOGLE_APPLICATION_CREDENTIALS = json_path)
    # Authenticate using the service account
    bq_auth(path = json_path)