java - 连接到 Google Firestore 时出现未经身份验证的问题

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

我正在使用 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/

相关文章:

java - "Illegal Start of action"和 "; expected"编译器错误

java - JMS 和 HornetQ

firebase - 如何将 displayName 添加到 Firebase 用户? ( flutter/Dart )

firebase - flutter firebase auth 应用栏标题的当前用户电子邮件

swift - 从 googleSignIn 进行身份验证后,如何从 AppDelegate 继续执行?

ios - Firebase 忘记密码 - 如何识别用户是使用电子邮件还是 Facebook 登录?

java - 恢复操作栏

java - 为什么 LinkedList 在添加到列表末尾时比 ArrayList 慢?

firebase - 无法在新的 Firebase 控制台中联系 Firebase 支持

ios - 如何使用 FBSDKLoginButton 注销? (奇怪的错误,因为 Facebook 假设我已登录)