I am getting error while sending message using Firebase
cloud messaging admin API
.
Error message is below
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" } }
Let me put my admin configuration here..
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);
Message sending code is below
// 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 dependencies that i am using is following
<dependency>
<groupId>com.google.firebase</groupId>
<artifactId>firebase-admin</artifactId>
<version>5.9.0</version>
</dependency>
So can anyone help me in this? What am I doing wrong?
Yet another cause of this is that your message is too large:
Notification messages can contain an optional data payload. Maximum payload for both message types is 4KB, except when sending messages from the Firebase console, which enforces a 1024 character limit.
https://firebase.google.com/docs/cloud-messaging/concept-options
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With