如何让 Firebase 与 Java 后端一起工作

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/40358940/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 22:38:26  来源:igfitidea点击:

How to get Firebase working with Java backend

javafirebasefirebase-realtime-database

提问by why_vincent

First of all I'd like to apologize if this question is to abstract or unsuitable for this site. I really don't know where else to ask.

首先,如果这个问题是抽象的或不适合本网站,我想道歉。我真的不知道还能去哪里问。

Currently I have developed apps in iOS and Android. They keep all their state in firebase, so everything is instantly persisted to the Firebase Realtime Database.

目前我已经在 iOS 和 Android 上开发了应用程序。他们将所有状态保存在 firebase 中,因此所有内容都会立即保存到 Firebase 实时数据库中。

Before a user is created I populate the realtime database manually with some data that is expected to be there so that the app can run, such as config data for the user. When I'm "done" using the app I view the data directly in the Firebase console.

在创建用户之前,我使用一些预期存在的数据手动填充实时数据库,以便应用程序可以运行,例如用户的配置数据。当我“完成”使用该应用程序时,我会直接在 Firebase 控制台中查看数据。

Now I want a backend to do the job I have done manually. I want the backend to be able to populate the realtime database and I want it also to be able to retrieve data from Firebase. I would like this to be done from a Java backend(Spring MVC but that might not be critical information right now).

现在我想要一个后端来完成我手动完成的工作。我希望后端能够填充实时数据库,并且我希望它也能够从 Firebase 检索数据。我希望这可以从 Java 后端完成(Spring MVC,但现在可能不是关键信息)。

How should I go about doing this? Googling hasn't gotten me that far(java+backend+firebase mostly tells me that "Firebase offers a backend to Android Java").

我该怎么做呢?谷歌搜索并没有让我走那么远(java+backend+firebase 主要告诉我“Firebase 提供了 Android Java 的后端”)。

If this is the wrong place to post this, then please suggest where I can post it instead.

如果这是张贴这个错误的地方,那么请建议我可以在哪里张贴。

Edit: I am aware of the Server SDK. I am rather referring on how to implement this in what would typically be a stateless rest solution than specifically how the methods in the Server SDK are executed.

编辑:我知道服务器 SDK。我指的是如何在通常是无状态休息解决方案中实现这一点,而不是具体如何执行服务器 SDK 中的方法。

采纳答案by Alex Shutov

Firebase has its own RestApi, you can use it in your api https://firebase.google.com/docs/database/rest/start

Firebase 有自己的 RestApi,你可以在你的 api https://firebase.google.com/docs/database/rest/start 中使用它

回答by Shrinivas

Firebase also provides dependencies to work with Firebase Realtime Database.

Firebase 还提供了与 Firebase 实时数据库配合使用的依赖项。

Gradle Dependency:

Gradle依赖:

dependencies {
  implementation 'com.google.firebase:firebase-admin:6.3.0'
}

Maven Dependency:

Maven 依赖:

<dependency>
  <groupId>com.google.firebase</groupId>
  <artifactId>firebase-admin</artifactId>
  <version>6.3.0</version>
</dependency>

For more details visit Docs : https://firebase.google.com/docs/admin/setup#add_firebase_to_your_app

有关更多详细信息,请访问文档:https: //firebase.google.com/docs/admin/setup#add_firebase_to_your_app