27

I'm implementing a push notification server with GCM. I send a post request with a sender ID (application key) that I got from Google API Console, and a registration ID that I got from the GCM service.

The posted JSON includes one registration ID. I always get the same response:

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

What might be the problem? What am I doing wrong?

2

11 Answers 11

33

Please uninstall your Android app from the device and run the app again.

Now you will get a new registration Id. That may solve your MismatchSenderId problem in a specific case (Sometimes it happens If you change/refresh your API key, but still using the old registration key). In my case, I got the registration Id first for my device and then I changed my API Key (on Google GCM server) and then I got MismatchSenderId error. Finally, I uninstalled my Android app from the device and the problem got solved.

5
  • 4
    Great answer +1 from me.
    – Antony
    Aug 20, 2012 at 14:22
  • 2
    Once I got my ID's all correct, it still wasn't working. This solution did the trick for me. +1
    – Jacksonkr
    Nov 5, 2012 at 17:36
  • 2
    After wasting about 2 hours and creating a new project on Google Apis, this was the solutions which I should have tried earlier. I had never thought of this and could have wasted many more hours on trying to figure out why the hell was my GCM not working. Sometimes lack of guidance and documentation from Google makes life really difficult.
    – zeeshan
    Oct 13, 2014 at 15:49
  • This isn't giving me a new ID.
    – Keavon
    Jan 24, 2015 at 6:05
  • same issue stackoverflow.com/questions/35812304/…
    – albert
    Mar 5, 2016 at 10:20
23

See the Stack Overflow post Why do I get "MismatchSenderId" from GCM server side?.

From the URL above:

double check the Sender ID and API_KEY, they must match or else you will get that MismatchSenderId error. In the Google API Console, look at the URL of your project:

https://code.google.com/apis/console/#project:xxxxxxxxxxx

The xxxxxxxxx is the project ID, which is the sender ID.

Some people are reporting issues using the "Key for Server Apps" type of keys, but having success using the Browser Key type instead. Personally, the Server Key type works for me, but try both, YMMV.

5
  • 1
    Sorry, but this answer is incorrect. Use the API Key labeled for Browsers. For some reason the IP Restricted ones aren't currently working (I'm developing as we speak). Jul 5, 2012 at 13:48
  • Actually, the server key works fine here. I'm the author of PushSharp and I've had success using the key for server app, however I've edited my answer to suggest trying both if the server key does not work.
    – Redth
    Jul 5, 2012 at 15:34
  • Actually Redth, that's a good idea. Clearly it's safer to use the Server specific key, but I've generated one for several different servers without any luck whatsoever. Jul 6, 2012 at 8:05
  • 4
    You should use "Project Number" (i.e. numeric ID) for Sender ID, not the "Project ID". Oct 27, 2014 at 23:59
  • can you help stackoverflow.com/questions/35812304/…
    – albert
    Mar 5, 2016 at 10:20
8

Log in to Google Cloud Console

See example in picture attached:

enter image description here

5

You should use "Project Number" (i.e. numeric ID) for Sender ID, not the "Project ID"

2

This error for sure because you specified a wrong SenderID when you register your device:

Here is a sample of register request (fiddler)

POST https://android.clients.google.com/c2dm/register3 HTTP/1.1 Host: android.clients.google.com Connection: keep-alive Content-Length: 83 Authorization: AidLogin 51734556544354357:9087138434543543508 Content-Type: application/x-www-form-urlencoded User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.99 Safari/537.36 Accept-Encoding: gzip, deflate Accept-Language: en-US,en;q=0.8,ar;q=0.6,fr;q=0.4

app=gpYOURAppHereloin&device=5112132132137117&sender=YourApplicationIDHere

You can find your SenderID by below steps

  1. Open the Google Developers Console.
  2. a page appears that displays your project ID and project number. For example, Project Number: 67023432432. Copy down your project number and use it as the GCM sender ID.

more info:

1
  • 1
    That first value is device id in the aidlogin but what's the second value?
    – NotGI
    Aug 29, 2016 at 10:30
2

I was copying code from a tutorial but forgot to change the project number in the source code. It was generating an ID for the tutorial author's project rather than mine, so check that you change your source code on the Android app!

0

Generate an API key from the API Console. Use browser app key in backend and use the project id as the sender id in your client code.

2
  • This is not working... When I use the project id, I get an INVALID_SENDER when trying to register. When I use the email address associated with the api console project, it registers successfully, but I still get the MismatchSenderID error too...
    – Redth
    Jul 3, 2012 at 14:46
  • see this link stackoverflow.com/questions/11242743/… i have use browser api key and it working fine in my case.
    – Sanket
    Jul 4, 2012 at 5:18
0

I had the same problem, but I made a stupid stupid thing: I had multiple projects in google console and I generated the registration Id for a project number that belongs to a project and I tried to send notifications to a Api key that belongs to another project. First step at this error is to check the project with that you work.

1
  • Log in in console.developers.google.com, search for the project (in case you have created multiple projects; or select the only one) and check if its Project Number is the same as the project number that you are using in your application. My problem was that I have multiple projects created in google developers console .. Nov 18, 2015 at 7:49
0

Note that if your Sender ID changes, Google Play Services's com.google.android.gms.gcm.GoogleCloudMessaging.register() method will keep returning the original registration id regardless of the new Sender(s) ID. You would need to invoke same class' unregister() method for Google Play Services to refresh and wipe out previous stale cached values.

See API info here: com.google.android.gms.gcm.GoogleCloudMessaging.register()

As an alternative, you can always delete app's data or uninstall-reinstall as noted in a previous answer but this is something far from acceptable in a production environment.

In case you have changed GCM settings and your Sender ID(s), apps must know that they need to unregister and register anew into GCM. One simple way to achieve this is pushing a new version to the Play Store and let users download the update and have this version do the work at its first execution, albeit this will not count apps that for some reason don´t get updated.

On top of that, if you are storing registration ids in preferences or a database, don´t forget to refresh its value when the app gets updated because updates could imply id regeneration and it could be the case that your code and not GCM is the one that is wrongly caching previous ids. Follow general guidelines here: General client-side implementation guidelines

0

I have a similar problem when I was testing out the Google Sample code found here https://github.com/GoogleCloudPlatform/gradle-appengine-templates/tree/master/GcmEndpoints and What XYZ said really helped me resolve this issue.

I was able to send the messages to my phone from my google app engine API Explorer under the messaging.messagingEndpoint.sendMessage method however in the google app engine console logs, it always said MismatchSenderId. The error logged when clearly there was not supposed to be an error bugged me.

MismatchSenderId

I was really confused and here is how I managed to resolve this:

  1. Uninstall your android app from your phone.
  2. Reinstall your android app and take note of the reg ID.
  3. Go onto API explorer under Services > registration API v1 > registration.listDevices and list all your RegID for GCM.
  4. Copy this list somewhere - to notepad.
  5. Go onto API explorer under Services > registration API v1 > registration.unregister and unregister all the regID that does not match to the one used by your app.

Retry sending the message and this time it should work without the error being recorded in the google app engine console logs.

0

You need to check the source of your registration id, you can not use a C2DM registration id within a GCM message post. From Google's Doc :

C2DM and GCM are not interoperable. For example, you cannot post notifications from GCM to C2DM registration IDs, nor can you use C2DM registration IDs as GCM registration IDs. From your server-side application, you must keep track of whether a registration ID is from C2DM or GCM and use the proper endpoint.

As you transition from C2DM to GCM, your server needs to be aware of whether a given registration ID contains an old C2DM sender or a new GCM project number. This is the approach we recommend: have the new app version (the one that uses GCM) send a bit along with the registration ID. This bit tells your server that this registration ID is for GCM. If you don't get the extra bit, you mark the registration ID as C2DM. Once no more valid registration IDs are marked as C2DM, you can complete the migration.

Another thing need to pay attention is the SENDER_ID, the format of SENDER_ID is the numeric one if you use InstanceID to get RegistrationID, like

    InstanceID instanceID = InstanceID.getInstance(this);
    String token = instanceID.getToken(SENDER_ID, GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);

The SENDER_ID could not use the project name, please use https://developers.google.com/mobile/add to get the "Server API Key" and the "Sender ID".

Not the answer you're looking for? Browse other questions tagged or ask your own question.