Mismatch Sender ID issue while migrating from GCM to FCM

Can sender IDs be different for the same Google and Firebase project?

Niharika Arora
Feb 7, 2019 · 3 min read

Yes, It can happen when GCM and FCM are running on different Google cloud projects.

Image for post
Image for post
Resolve mismatch sender id issue when migrating from GCM to FCM

In this blog, I am sharing one of the many experiences I had while implementing Push Notifications using Firebase Cloud Messaging(FCM) for 1mg App.

Push Notification and GCM

Push notification is one of the major sources for an application to help engage users better. For this purpose, we started using Google’s Cloud Messaging(GCM) a couple of years ago. There was proper documentation on the Google developer site to include GCM in an application. We made our push services capable of sending notifications based on location, time of the day, special occasions, user actions, app versions and more.

Firebase (FCM)

A few years back we got Firebase Cloud messaging which was capable of doing much more than GCM.

But as our needs were getting fulfilled through GCM, we didn’t migrate to FCM at that time.

GCM Deprecation and Migration from GCM to FCM

Now that GCM has been deprecated, we’ve finally moved to FCM. You can get the documentation here. I started testing my application with FCM using the same sender ID and API key we had for GCM(As per google doc, sender ID will remain same while migrating from GCM to FCM for the same package). I didn’t get the notification on the device. After checking the response on Postman, I got this -

{"multicast_id":xxxx,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"MismatchSenderId"}]}

I had no clue where I had made a mistake. I searched on Google, tried different things but in vain.

GCM and FCM on different Google Cloud Projects

We had been running GCM on our first cloud project created some years ago. So when we migrated our GCM project to FCM, all our enhancements were on a different cloud project.

This presented a very tricky situation. FCM and GCM had different sender ids. So, we had to use one token for sending messages to our old users on GCM and another one to send messages to new users on FCM.

Solution

What we wanted was to send messages on one key, and receive messages across our entire user base. There was no documented method to do this on Firebase. After several hours of digging, I found a solution. Normally we use this method to generate a firebase token -

FirebaseInstanceId.getInstance().getToken()

But to handle a case where sender IDs are different we can use -

FirebaseInstanceId.getInstance().getToken(“old-sender-id”, FirebaseMessaging.INSTANCE_ID_SCOPE)

The above line of code helps to generate a token from the old sender id (from different could project) and use that to receive messages via FCM.

Please feel free to share your opinion in comments.

If you liked this blog, hit the 👏 . Stay tuned for the next one!

1mg Technology

India's most trusted consumer health platform.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store