java - Spring Boot - Firebase 管理 SDK - 通知

标签 java firebase spring-boot firebase-cloud-messaging firebase-admin

我尝试初始化 Admin SDK,但在服务帐户初始化时遇到 400 错误请求。它在我的 Windows 开发环境中运行得很好,但是当我在 Linux 中部署它时,我遇到了这个问题。

        SpringApplication.run(OrderApplication.class, args);

        FileInputStream serviceAccount = new FileInputStream(GlobalValue.serviceAccount);

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

        FirebaseApp.initializeApp(options);

    }

我正在从属性文件中读取文件路径。

service.account=/home/service-account.json

我正在尝试发送推送通知,当时遇到了问题。


        try {
            MulticastMessage multicastMessage = MulticastMessage.builder().addAllTokens(lDeviceTokens)
                    .setNotification(new Notification(title, message)).build();

            BatchResponse response = FirebaseMessaging.getInstance().sendMulticast(multicastMessage);
            // See the BatchResponse reference documentation // for the contents of
            // response.
            System.out.println(response.getSuccessCount() + " messages were sent successfully");
        } catch (FirebaseMessagingException e) {
            e.printStackTrace();
            System.out.println(e.getLocalizedMessage());
        }
    }

跟踪

. java: 141 S)
at org . apache . tomcat . util .neC . Socket ProcessorBase . run (Socket ProcessorBas
e . java : 49)
at java . concurrent . ThreadPooIExecuCor . runWorker (ThreadPooIExecuC01 .
java : 1149)
at java . concurrent . ThreadPooIExecucor$Worker . run (ThreadPooIExecuC01
. java : 624)
at org . apache . ComcaC . util . Chreads . TaskThread$WrappingRunnabIe . run (TaskTh
read . java : 61)
at java. lang . Thread. run (Thread. java : 7 48)
Caused by: java.io. IOExcepCion: Error getting access token for service account :
400 Bad Request
"error" • "invalid grant"
"error description" • "Invalid JWT: Token must be a short—lived token (60 minut
es) and in a reasonable timeframe. Check Y2ur iat and exp values and use a clock
with skew to account for clock differences between systems . "
at com.google . auth . oauCh2 . ServiceAccounCCredenCiaIs . refreshAccessToken ( S
erviceAccounCCredenCiaIs . java : 401)
at com.google . auth . oauCh2 . OAuth2CredenCiaIs . refresh (OAuth2CredenCiaIs . j a
va:181)
at com.google . auth . oauCh2 . OAuth2CredenCiaIs . geCRequesCMeCadaCa (OAuth2Cre
dentials . java : 167)

最佳答案

如果有帮助,请查看这些链接,当您迁移到 Linux 时,这似乎是服务器时间问题

Google Client Invalid JWT: Token must be a short-lived token

Token must be a short-lived token and in a reasonable timeframe

关于java - Spring Boot - Firebase 管理 SDK - 通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56266838/

相关文章:

java - Hibernate CriteriaBuilder 为以驼峰命名法编写的属性生成无效查询

Java查询求解拉伸(stretch)因子

java - 将洗好的牌加入队列

java - 在 java 中将 xml 配置文件用于我的应用程序的最佳方法是什么?

firebase - 错误 : storage/object-not-found when trying to upload large image file

java - 为什么 Logback 是 Spring Boot 中的默认日志记录框架?

java - 无法在 Spring Boot 2.0.0 中 Autowiring 身份验证管理器

java - 使用idea编译spring5源码出现错误

javascript - Firebase 搜索查询给出不同的结果

firebase - 如何在flutter firebase应用程序中搜索并向附近的人发送通知?