我想要实现的是打开与我的 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:
最佳答案
关于java - Firebase 连接在 SpringBoot 中的 Linux 上不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47879629/