【问题标题】:For Firestore which Dependencies needs to be added, to write Java code?Firestore需要添加哪些Dependencies,写Java代码?
【发布时间】:2018-07-05 08:00:05
【问题描述】:

我正在使用 Java 代码编写代码来监听 Firestore DB 中的数据更改。 我已经使用 maven 添加了以下依赖项:

  1. com.google.cloud:google-cloud-firestore:0.32.0-beta
  2. com.google.firebase:firebase-admin:5.8.0

但在编写代码时,我无法解析以下导入:

  1. com.google.cloud.firestore.DocumentChange
  2. com.google.cloud.firestore.DocumentChange.Type
  3. com.google.cloud.firestore.EventListener
  4. com.google.cloud.firestore.ListenerRegistration

需要做什么或需要添加哪些依赖项?

【问题讨论】:

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


    【解决方案1】:

    如果您使用的是 Firebase 项目,您只需要管理 SDK:

    com.google.firebase:firebase-admin:5.8.0
    

    它对使其工作所需的所有其他内容具有传递依赖关系。我不会尝试引入 Cloud 依赖项,除非您绝对知道出于某种原因需要它们。

    此外,请删除您当前为 com.google.cloud.* 拥有的导入,并改为使用由管理 SDK 公开的位于 com.google.firestore 中的同名对象。

    【讨论】:

    • 您好,Doug,我删除了 com.google.cloud。现在,我找不到任何可以记录 Firestore DB 更改的 API。我需要将 Firestore DB 上的任何写入(创建/更新/删除)注册到包含信息的文本文件中,该信息将由单独的应用程序进一步读取。
    • 您导入 Admin SDK 的方式一定有问题。使用 gradle 在 IntelliJ 中工作时,我在查找相关类时没有任何问题。
    • 可以使用什么API?我从 GitHub 中提取了以下代码:
    • db.collection("cities").whereEqualTo("state", "CA").addSnapshotListener(new EventListener() public void onEvent(@Nullable QuerySnapshot 快照,@Nullable FirestoreException e ) { for (DocumentChange dc : snapshots.getDocumentChanges()) { switch (dc.getType()) { case MODIFIED: System.out.println("Modified city"); break; } } if (!future.isDone() ) { future.set(snapshots.getDocumentChanges()); } } 方法 addSnapshotListener、EventListener、getDocumentChanges、getType、getData 的问题
    猜你喜欢
    • 1970-01-01
    • 2015-02-07
    • 2023-03-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多