我正在寻找一种从 java 代码中以编程方式调用firestore 导入/导出功能的方法。
到目前为止,我发现漂亮的Firestore 客户端库还不支持导入/导出调用。但是更底层的rest/grpc api已经支持它们。使用java 库我尝试了以下操作:
Firestore firestoreApi = new Firestore
.Builder(UrlFetchTransport.getDefaultInstance(), new GsonFactory(), null)
.setApplicationName(SystemProperty.applicationId.get())
.build();
GoogleFirestoreAdminV1beta2ImportDocumentsRequest importRequest = new GoogleFirestoreAdminV1beta2ImportDocumentsRequest();
importRequest.setInputUriPrefix(String.format("gs://{}/{}/", BUCKET, image));
GoogleLongrunningOperation operation = firestoreApi
.projects()
.databases()
.importDocuments("projects/" + SystemProperty.applicationId.get() + "/databases/(default)", importRequest)
.execute();
遗憾的是,在应用引擎中运行时缺少权限:
com.google.api.client.googleapis.json.GoogleJsonResponseException: 401
{
"code": 401,
"errors": [
{
"domain": "global",
"location": "Authorization",
"locationType": "header",
"message": "Login Required.",
"reason": "required"
}
],
"message": "Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",
"status": "UNAUTHENTICATED"
我无法获得正式的登录方式来工作,因为 firestore 构建器没有接受AppEngineCredentials
.
我已经检查了似乎也不支持这些方法的python客户端库(还)。有谁知道我如何使用旧的rest api登录或获取支持这些方法的客户端库(请在应用引擎上运行一些语言:))
谢谢阅读!卡斯滕