I have this piece of code:
log.info("Sending message to topic: " + topic);
// This registration token comes from the client FCM SDKs.
String registrationToken = "AAAAVjsyE68:APA91bHOdV7whbcjOKxohCsw9TBuZaYfvqSiNk6uSpQ-_8THdRjdWepCa-fxrqvJjePwls-eObnD4tzIaYOZYTGAzped3nWI6rer91f1IoLvBf15M4NZEhsdPu-goKHe2zp4nDG";
// See documentation on defining a message payload.
Message message = Message.builder()
.setTopic(topic)
.setNotification(Notification.builder()
.setTitle("Your notification title")
.setBody("Your notification message")
.build())
.setToken(registrationToken)
.build();
// Send a message to the device corresponding to the provided
// registration token.
String response = FirebaseMessaging.getInstance().send(message);
// Response is a message ID string.
log.info("Successfully sent message: " + response);
but I have this error:
aused by: java.lang.IllegalArgumentException: Exactly one of token, topic or condition must be specified
at com.google.common.base.Preconditions.checkArgument(Preconditions.java:143)
at com.google.firebase.messaging.Message.<init>(Message.java:80)
at com.google.firebase.messaging.Message.<init>(Message.java:40)
at com.google.firebase.messaging.Message$Builder.build(Message.java:295)
at com.mysticplanets.service.FirestoreMessageService.sendMessageToTopic(FirestoreMessageService.java:50)
The error says:
Exactly one of token, topic or condition must be specified
Your Message builder specifies both topic and token. You will have to decide which one you are using to target this message - it can't be both.
This is repeated in the API documentation for Message:
The recipient information must contain exactly one token, topic or condition parameter.