如何在Android中使用service_account.json文件设置用于BigQuery身份验证的GoogleCredentials?

时间:2019-05-16 11:38:54

标签: android firebase google-bigquery firebase-analytics

我正在尝试使用BigQuery将GoogleCredentials设置为android,但是使用_service_account.json_设置凭据无效。

在获取service_account.json文件时,它抛出 FileNotFoundException 错误,当我尝试使用 InputStream 加载文件时,会发生相同的错误。

这是我的代码

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();

注意:我将 service_account.json 放在 app / assets 文件夹

0 个答案:

没有答案