无法使用最新的Firebase SDK依赖项解析FirebaseOptions [英] Can not resolve FirebaseOptions using latest Firebase SDK dependency

查看:195
本文介绍了无法使用最新的Firebase SDK依赖项解析FirebaseOptions的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过以下教程将spring-boot rest api与Firebase集成: savicprvoslav

I am trying to integrate my spring-boot rest api with Firebase by these following tutorial: savicprvoslav

我需要使用由前端应用程序生成的Firebase SDK 验证userTokenId .

I need to verify the userTokenId using Firebase SDK which is generated by a front end application.

上面使用的git指南

<dependency>
            <groupId>com.google.firebase</groupId>
            <artifactId>firebase-server-sdk</artifactId>
            <version>3.0.3</version>
        </dependency>

已被弃用的

,建议使用最新的Firebase SDK [ maven存储库]

which is already deprecated and suggesting to use latest Firebase SDK [ maven repository]

根据Firebase SDK集成指南,我们应使用

According to the Firebase SDK integration guide we should use

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

旧惯例:

InputStream inputStream = FirebaseConfig.class.getClassLoader().getResourceAsStream(configPath);

        FirebaseOptions options = new FirebaseOptions.Builder().setServiceAccount(inputStream)
                .setDatabaseUrl(databaseUrl).build();

新习惯:

FileInputStream serviceAccount = new FileInputStream("path/to/serviceAccountKey.json");

FirebaseOptions options = new FirebaseOptions.Builder()
  .setCredentials(GoogleCredentials.fromStream(serviceAccount))
  .setDatabaseUrl("https://<DATABASE_NAME>.firebaseio.com/")
  .build();

我尝试使用它(删除了旧的),但是它无法解决许多依赖项,例如 FirebaseOption ,只能通过旧的Maven依赖项来解决( firebase-server-sdk 3.0.3 )

I have tried to use it (removed the old one) but it failed to resolve lots of dependencies like FirebaseOption which can only resolved by old maven dependencies(firebase-server-sdk 3.0.3)

我真的很困惑!找不到任何更新的示例项目.一个示例项目将非常有帮助(初始化firebase sdk的示例代码).

I am really very confused ! Can not find any updated example project. A sample project will very helpful (example code which initialize the firebase sdk ) .

有人可以帮忙吗?

感谢

推荐答案

幸运的是,Firebase已更新了他们的文档,现在在maven configuraiton下提出了这些建议,从而完美地解决了该问题.我认为这是一个过时的文档问题.

Fortunately Firebase has updated their documentation and now suggesting these below maven configuraiton , which resolved the problem perfectly. I think it was a outdated documentation issue.

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

请点击此链接 Firebase SDK安装指南

此外,如果您落后于企业代理,则需要这样设置代理:

In addition , if you are behind corporate proxy, you need to set proxy like this:

System.setProperty("https.proxyHost", "your_proxy_host");
System.setProperty("https.proxyPort", "your_proxy_port");

因此初始化Firebase实例的完整代码为:

so complete code to initialize Firebase instance is:

 URL fileUrl = FirebaseConfig.class.getClassLoader().getResource(configPath);
FileInputStream fisTargetFile = new FileInputStream(fileUrl.getFile());
System.setProperty("https.proxyHost", "your_proxy_host");
System.setProperty("https.proxyPort", "your_proxy_port");
    FirebaseOptions options = new FirebaseOptions.Builder()
            .setCredentials(GoogleCredentials.fromStream(fisTargetFile))
            .setDatabaseUrl(databaseUrl)
            .build();
    FirebaseApp.initializeApp(options);

希望对其他人有帮助.

这篇关于无法使用最新的Firebase SDK依赖项解析FirebaseOptions的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆