【问题标题】:Firebase connection not working on Linux in SpringBootFirebase 连接在 Spring Boot 中的 Linux 上不起作用
【发布时间】:2017-12-19 22:32:03
【问题描述】:

我想要实现的是打开与我的 firebase 数据库的连接并获取一些我需要解析的数据。我正在使用 Spring Boot 框架、firebase 的 admin sdk、kotlin 和 gradle 运行 Spring。在 Windows 10 上,它按预期工作,但是当我尝试在我的 linux 服务器上运行 .jar 文件时,它没有得到任何数据或错误。它卡在 ValueEventListener 上。我安装了 ufw,但禁用它或添加端口 5228:5230 (tcp/udp) 并没有解决问题。

    val dataMinifiedRef = database.reference.child("minifiedData").child("areas")
    dataMinifiedRef.addListenerForSingleValueEvent(object : ValueEventListener {
        override fun onCancelled(error: DatabaseError?) {
            log.info(error!!.message)
        }

        override fun onDataChange(dataSnapshot: DataSnapshot) {
            log.info("Got data")
        }
    })

编辑: 这就是我解析服务帐户的方式。

    val str = "{\n" +
              ...
              "}\n"

    // convert String into InputStream
    val serviceAccount = ByteArrayInputStream(str.toByteArray())

    val options = FirebaseOptions.Builder()
            .setCredentials(GoogleCredentials.fromStream(serviceAccount))
            .setDatabaseUrl("https://xxx.firebaseio.com")
            .build()

我收到以下错误。

Tue Dec 19 15:31:41 CET 2017 [DEBUG] com.google.firebase.database.connection.PersistentConnection‌​: pc_0 - Trying to fetch auth token 
Tue Dec 19 15:31:41 CET 2017 [DEBUG] com.google.firebase.database.connection.PersistentConnection‌​: pc_0 - Error fetching token: java.io.IOException: Error getting access token for service account:

【问题讨论】:

  • 很难说出了什么问题。但是如果你 enable debug logging 你可能会在输出中得到一个线索。
  • 它给你日志“得到数据”?
  • 不,没有日志显示
  • @FrankvanPuffelen 我将日志级别设置为调试,现在 firebase 将其输出:Tue Dec 19 15:31:41 CET 2017 [DEBUG] com.google.firebase.database.connection.PersistentConnection: pc_0 - Trying to fetch auth token Tue Dec 19 15:31:41 CET 2017 [DEBUG] com.google.firebase.database.connection.PersistentConnection: pc_0 - Error fetching token: java.io.IOException: Error getting access token for service account:。我有一个字符串中的 service_account,我用 ByteArrayInputStream 解析它。我认为这是可行的,但我假设它无法连接到 firebase 本身?

标签: java linux spring firebase-realtime-database kotlin


【解决方案1】:

问题是我们的 Linux 服务器上的时间没有自动同步。我在他提到解决方案的地方找到了这个article。然后我关注了guide 并添加了与我们的服务器位置相同的 NTP 服务器。

【讨论】:

    猜你喜欢
    • 2014-08-16
    • 2017-01-29
    • 2019-12-25
    • 2016-01-12
    • 2016-11-04
    • 2021-06-18
    • 1970-01-01
    • 2018-12-08
    • 2018-09-24
    相关资源
    最近更新 更多