gpt4 book ai didi

java - Firebase 连接在 SpringBoot 中的 Linux 上不起作用

转载 作者:太空宇宙 更新时间:2023-11-04 05:16:57 25 4
gpt4 key购买 nike

我想要实现的是打开与我的 firebase 数据库的连接并获取一些我需要解析的数据。我正在使用 Spring Boot 框架、firebase、kotlin 和 gradle 的管理 sdk 来运行 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:

最佳答案

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

关于java - Firebase 连接在 SpringBoot 中的 Linux 上不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47879629/

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