【发布时间】:2017-10-07 23:48:03
【问题描述】:
我正在使用 Google Cloud Firestore Beta,并根据 google 提供的文档编写了一个非常简单的代码。我在执行它时收到一个未经身份验证的错误。代码如下,与文档中提供的一些sn-ps非常相似。
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:
[INFO] GCLOUD: java.util.concurrent.ExecutionException: com.google.api.gax.rpc.UnauthenticatedException: io.grpc.StatusRuntimeException: UNAUTHENTICATED
【问题讨论】:
-
在这里分享完整的堆栈跟踪:
-
验证您的 Firestore Api 密钥和 ID cloud.google.com/firestore/docs/solutions/search
标签: java firebase firebase-authentication google-cloud-firestore