0

I am trying to set up GoogleCredentials with BigQuery into android but setting up the credential using _service_account.json_ is not working.

It throws FileNotFoundException error while fetching the service_account.json file, When I try to load the file with InputStream the same error occurs.

This is my code

GoogleCredentials credentials;
File credentialsPath = new File("service_account.json");
try (FileInputStream serviceAccountStream = new FileInputStream(credentialsPath)) {
    credentials = ServiceAccountCredentials.fromStream(serviceAccountStream);
} // Instantiate a client.

BigQuery bigquery = BigQueryOptions.newBuilder().setCredentials(credentials).build().getService();

Note: I have place service_account.json under app/assets folder

Tamir Klein
  • 3,514
  • 1
  • 20
  • 38
  • See this https://stackoverflow.com/a/56147202/1031958 – Tamir Klein May 16 '19 at 11:52
  • @TamirKlein I want to set up into android, So I need a reference for Android only – Saumil Vaghela May 16 '19 at 12:02
  • Please provide your code exampls – Tamir Klein May 16 '19 at 12:14
  • GoogleCredentials credentials; File credentialsPath = new File("service_account.json"); try (FileInputStream serviceAccountStream = new FileInputStream(credentialsPath)) { credentials = ServiceAccountCredentials.fromStream(serviceAccountStream); } // Instantiate a client. BigQuery bigquery = BigQueryOptions.newBuilder().setCredentials(credentials).build().getService(); I have place service_account.json under app/assets folder – Saumil Vaghela May 16 '19 at 12:53
  • 1
    Hi Saumil, could you please edit your question adding the commented code, so it will be more helpful for the upcoming readers. Thanks :) – Pol Ortiz May 16 '19 at 14:10
  • Looking at BigQuery [example](https://cloud.google.com/bigquery/docs/authentication/service-account-file#bigquery_client_json_credentials-java): `File credentialsPath = new File("service_account.json"); // TODO: **update to your key path.**`. Why you are not using the correct path to the file /app/assets/service_account.json? – Tamir Klein May 16 '19 at 16:16
  • I have fixed the issue, Thanks :) – Saumil Vaghela May 23 '19 at 12:57

0 Answers0