Firebase FCM MismatchSenderID

2020-02-06 10:33发布

问题:

I have my client app with Android installed in several devices. I also have my Server app that send messages to those apps. The problem is that some devices receive the messages and other don't. I get the error "MismatchSenderId" when sending the message to those devices.

I divided the problem, so I open the firebase console and send notifications to my apps (I have the Token for each of them). So, using the console app, I get errors on the same devices that using my server. But as I said, every device is using the same app.

Any help of the reason?

回答1:

So to start of, I'd point out the description for MismatchSenderId error:

A registration token is tied to a certain group of senders. When a client app registers for FCM, it must specify which senders are allowed to send messages. You should use one of those sender IDs when sending messages to the client app. If you switch to a different sender, the existing registration tokens won't work.

As per our discussion, it was pointed out that you created a new Firebase Project instead of importing your Google Project that you were using for GCM. From the new project, the google-services.json was generated and used for the app, which resulted for new tokens to be associated with the new Project's Sender ID. To visualize it properly:

  • GCM Registration Tokens > only receive messages from > Google Project (1st)

  • New Tokens > only receive messages from > Firebase Project (2nd)

As a solution, I advised for you to import the Google Project to the Firebase Console, generate a google-services.json from that Project and replace the one in your app with that, which associates the app to that (correct) project. This in turn created tokens that are now associated with your 1st Project.

  • GCM Registration Tokens > only receive messages > Google Project (1st)

  • New Tokens > now receive messages > Firebase Project (2nd) Imported Google Project (1st)

Hope that makes sense.


Good to mention from the discussion:

  • After applying the changes, you mentioned that the error persisted, but it was a different issue that was fixed by simply using the Server Key.

  • Linked a post during discussion.



回答2:

Supporting @AL's answer, basically you need to uninstall the app on all the devices and install the app again so that all devices receive new tokens that correspond with the newly connected firebase project database.