I'm doing a project using Spring Boot to send notifications to my React Native app. Since I'm using Expo to my React Native app, I did a different configuration following this tutorial and tested with Notifications composer from Firebase and worked well.
For the Spring Boot, I used this another tutorial to configure FCM, also I create a Private Key file from SDK admin in Firebase to use here:
try {
FirebaseOptions options = FirebaseOptions.builder()
.setCredentials(GoogleCredentials.fromStream(new ClassPathResource(MY_PRIVATE_KEY_FILE).getInputStream()))
.build();
if (FirebaseApp.getApps().isEmpty()) {
FirebaseApp.initializeApp(options);
}
} catch (IOException e) {
e.printStackTrace();
}
So I did a method to send the message using token from Server Key like this:
private String token="AAAAm_p0hoc:************************************";
public void sendPushNotificationWithData() {
PushNotificationRequest pushNotificationRequest = new PushNotificationRequest();
pushNotificationRequest.setMessage("Send push notifications from Spring Boot server");
pushNotificationRequest.setTitle("test Push Notification");
pushNotificationRequest.setToken(token);
Map<String, String> appData= new HashMap<>();
appData.put("name", "PushNotification");
try {
fcmService.sendMessage(appData, pushNotificationRequest);
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
}
}
But I'm just having this response from FCM:
POST https://fcm.googleapis.com/v1/projects/myproject/messages:send
{
"error": {
"code": 403,
"message": "SenderId mismatch",
"status": "PERMISSION_DENIED",
"details": [
{
"@type": "type.googleapis.com/google.firebase.fcm.v1.FcmError",
"errorCode": "SENDER_ID_MISMATCH"
}
]
}
}
I tried to make a new project into FireBase, update the private and server keys but still having the same response.
Is something I forgot to set up or am I doing it wrong?