firebase 云消息传递请求包含无效参数

标签 firebase google-cloud-messaging firebase-cloud-messaging

使用 Firebase 发送消息时出现错误云消息管理API .

错误信息如下

Caused by: com.google.api.client.http.HttpResponseException: 400 Bad Request { "error": { "code": 400, "message": "Request contains an invalid argument.", "errors": [ { "message": "Request contains an invalid argument.", "domain": "global", "reason": "badRequest" } ], "status": "INVALID_ARGUMENT" } }



让我把我的管理员配置放在这里..
FileInputStream serviceAccount = new FileInputStream("My service accout file.json");

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

FirebaseApp.initializeApp(options);

消息发送代码如下
// This registration token comes from the client FCM SDKs.
String registrationToken = "YOUR_REGISTRATION_TOKEN";

// See documentation on defining a message payload.
Message message = Message.builder().putData("score", "850").putData("time", "2:45").setToken(registrationToken).build();

// Send a message to the device corresponding to the provided
// registration token.
String response = FirebaseMessaging.getInstance().sendAsync(message).get();
// Response is a message ID string.
System.out.println("Successfully sent message: " + response);

我正在使用的 maven 依赖项如下
<dependency>
    <groupId>com.google.firebase</groupId>
    <artifactId>firebase-admin</artifactId>
    <version>5.9.0</version>
</dependency>

那么有人可以帮助我吗?我做错了什么?

最佳答案

我怀疑你的 registrationToken格式无效。它应该是 152 个字符。

要确认这一点,请尝试使用 setTopic("test") 构建您的消息而不是 setToken(registrationToken) .

关于firebase 云消息传递请求包含无效参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49124441/

相关文章:

android - 在 BroadcastReceiver 的 onReceive() 中创建 PendingIntent

android - 当应用程序更新时,FCM 是否更新注册 ID

ios - Flutter/FCM 通知未到达 Codemagic iOS 版本

android - 无法解析 : com. google.firebase :firebase-messaging:16. 0.5

ios - iPhone X 上未收到 Firebase 通知 FCM

ios - 最初从 firebase 获取无效的推送 token ,最后获取有效的推送 token

ios - Parse.com 推送通知 VS。适用于 iOS 的 Google Cloud 消息传递?

javascript - Firebase GeoFire : Is It Possible to Remove Multiple Keys at Once using geoFire. 删除()?

angularjs - 如何在 Angular 应用的 Karma 测试中模拟 Firebase

c# - 即将到来的 GCM 响应是 : Error=NotRegistered