我正在使用 Google Cloud Firestore Beta,并根据 google 提供的文档编写了一个非常简单的代码。我在执行时收到未经身份验证的错误。代码如下,与文档中提供的一些片段非常相似。
String keyPath = "mykeystore.json";
FirestoreOptions firestoreOptions = FirestoreOptions.getDefaultInstance().toBuilder().setProjectId("test-project-111").setCredentials(ServiceAccountCredentials.fromStream(new FileInputStream(keyPath))).build();
Firestore db = firestoreOptions.getService();
DocumentReference docRef = db.collection("users").document("alovelace");
// Add document data with id "alovelace" using a hashmap
Map<String, Object> data = new HashMap<>();
data.put("first", "Ada");
data.put("last", "Lovelace");
data.put("born", 1815);
//asynchronously write data
ApiFuture<WriteResult> result = docRef.set(data);
try
{
result.get();
} catch (InterruptedException e)
{
e.printStackTrace();
} catch (ExecutionException e)
{
e.printStackTrace();
}
I am getting the error at the "result.get()" line of the code. The error is as below:
[信息] GCLOUD:java.util.concurrent.ExecutionException:com.google.api.gax.rpc.UnauthenticatedException:io.grpc.StatusRuntimeException:未经身份验证
最佳答案
UNAUTHENTICATED issue while connecting to Google Firestore
测试版
这是 Cloud Firestore 的测试版。该产品可能会以向后不兼容的方式进行更改,并且不受任何 SLA 或弃用政策的约束。
Cloud Firestore is currently in beta release 。随着产品的成熟,功能可用性以及对产品集成和平台的支持将不断改进。有关 Cloud Firestore 中现有限制的更多信息,请参阅限制和配额文档
或验证您的 firestore Api key 和 ID Cloud Firestore Security Rules
关于java - 连接到 Google Firestore 时出现未经身份验证的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46626200/