Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to authenticate `com.google.cloud.bigquery.BigQuery` with service account

I want to use this library

com.google.cloud.bigquery.BigQuery

as in the example:

https://cloud.google.com/bigquery/create-simple-app-api

However I want to authenticate the BigQuery client with service account.

How can I do this?

I see only a default credentials way.

  BigQuery bigquery =
                new BigQueryOptions.DefaultBigqueryFactory().create(BigQueryOptions.defaultInstance());
like image 365
Elad Benda2 Avatar asked Nov 20 '25 08:11

Elad Benda2


1 Answers

Try using setCredentials and ServiceAccountCredentials.fromStream while building the service.

BigQuery bigquery = BigQueryOptions.newBuilder()
    .setCredentials(
       ServiceAccountCredentials.fromStream(
         new FileInputStream("your_json_service_keyfile.json"))
    )
    .build().getService()

This ought to be better documented in Google's API doc.

Hope it helps, it's my first answer on stackoverflow :-)

like image 125
madll Avatar answered Nov 22 '25 23:11

madll



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!