gpt4 book ai didi

android - 从 GAE 开发服务器使用 Firestore 时出现未经验证的异常

转载 作者:太空狗 更新时间:2023-10-29 13:06:47 25 4
gpt4 key购买 nike

我正在制作一个使用 Cloud Endpoints Framework 作为后端 API 的 Android 应用。我正在使用 App Engine 开发服务器测试后端。在其中一个后端函数中,我尝试调用以从 Firestore 数据库获取文档,但出现此错误:

com.google.api.server.spi.SystemService invokeServiceMethod SEVERE: exception occurred while calling backend method java.util.concurrent.ExecutionException: io.grpc.StatusRuntimeException: UNAUTHENTICATED at com.google.common.util.concurrent.AbstractFuture.getDoneValue(AbstractFuture.java:500) at com.google.common.util.concurrent.AbstractFuture.get(AbstractFuture.java:479) at com.google.api.core.AbstractApiFuture.get(AbstractApiFuture.java:57) ...

我相信我已经正确设置了服务帐户。我将环境变量 GOOGL_APPLICATION_CREDENTIALS 设置为服务帐户 key 的路径。我还遵循实例化和调用 Firestore 的指南:

import com.google.cloud.firestore.Firestore;
import com.google.cloud.firestore.FirestoreOptions;
FirestoreOptions firestoreOptions =
FirestoreOptions.getDefaultInstance().toBuilder()
.setProjectId(projectId)
.build();
Firestore db = firestoreOptions.getService();
db.collection(collectionId).get().get();

我是否缺少能够从 GAE 调用 Firestore 的东西?

最佳答案

在与这个问题斗争了一段时间之后,我偶然发现了一个临时解决方法。似乎数据库确实尚未经过身份验证,在获取服务后添加调用以获取请求元数据似乎触发了身份验证......

Firestore db = firestoreOptions.getService();

try {
// somehow without this it does not work on the local server
db.getOptions().getCredentials().getRequestMetadata();
} catch (IOException e) {
e.printStackTrace();
}

... // db access works on local server!

关于android - 从 GAE 开发服务器使用 Firestore 时出现未经验证的异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46934345/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com