Spring Boot-Firebase Admin SDK-通知

时间:2019-05-23 01:08:00

标签: 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)

1 个答案:

答案 0 :(得分:0)

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

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

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