连接到Google Firestore时出现UNAUTHENTICATED问题

时间:2017-10-07 23:48:03

标签: java firebase firebase-authentication google-cloud-firestore

我正在使用Google Cloud Firestore Beta并根据Google提供的文档编写了一个非常简单的代码。我在执行时遇到UNAUTHENTICATED错误。代码如下所示,与文档中提供的一些代码段非常相似。

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

1 个答案:

答案 0 :(得分:0)

  

连接到Google Firestore时出现无法识别的问题

<强>β

这是Cloud Firestore的测试版。此产品可能以向后不兼容的方式更改,不受任何SLA或弃用策略的约束。

Cloud Firestore is currently in beta release。随着产品的成熟,功能可用性以及对产品集成和平台的支持将不断改进。有关Cloud Firestore中现有限制的更多信息,请参阅限制和配额文档

验证您的Firestore Api密钥&amp; ID Cloud Firestore Security Rules