2

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?

  • Please check if the server key and the sender ID are correct. If they are correct, could you please check which Firebase PRoject your current Spring Boot app is linked to and confirm if you are using the right Server Key from that project. – Nibrass H Mar 26 '21 at 21:50
  • Please have a look into the following [post](https://stackoverflow.com/questions/37863106/fcm-getting-mismatchsenderid) where you can see that most of the times this error is given due to not having the right server key. – Nibrass H Mar 26 '21 at 21:51
  • You can also follow this [Tutorial](https://medium.com/@singh.pankajmca/fcm-integration-with-spring-boot-to-send-push-notification-from-server-side-1091cfd2cacf) which explains step by step FCM Integration with Spring Boot To Send Push Notification From Server Side. – Nibrass H Mar 26 '21 at 21:52

0 Answers0