gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 05:20:26 33 4
gpt4 key购买 nike

我尝试初始化 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/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com