我正在尝试使用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 文件夹
下