This question already has answers here:
Why do I get "MismatchSenderId" from GCM server side?
(11 answers)
Closed 7 years ago.
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?
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.
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.
Log in to Google Cloud Console
See example in picture attached:
You should use "Project Number" (i.e. numeric ID) for Sender ID, not the "Project ID"
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
Open the Google Developers Console.
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:
Getting Started : http://developer.android.com/google/gcm/gs.html
Mismatched Sender error : http://developer.android.com/google/gcm/http.html#Mismatched_Sender
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!
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.
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.
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
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.
I was really confused and here is how I managed to resolve this:
Uninstall your android app from your phone.
Reinstall your android app and take note of the reg ID.
Go onto API explorer under Services > registration API v1 > registration.listDevices and list all your RegID for GCM.
Copy this list somewhere - to notepad.
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.
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".
Related
Question: On a server side, given a Firebase Cloud Messaging Token (only the token), is there a way to determine that I already have a token for this specific device?
I got 3 tokens from my device, that all have the same prefix (before the colon)
eWckfbcqTjC9Nxm_BT8alU:APA91bHjsrbm27Qrm...
eWckfbcqTjC9Nxm_BT8alU:APA91bH1_COORkdVi...
eWckfbcqTjC9Nxm_BT8alU:APA91bGleAJmFgq4F...
Tokens from different device have completely different prefix.
Is it safe to assume, that if the prefix is the same, then the device is the same?
Situation: I have a method that accepts a CompanyID and a FCM Token to be bound to the company. Problem is, the app sends a new token rather frequently while deleting the old one only on app's side.
If I just add this token (insert into) to the DB, I'll get lots of FCM error messages while sending push notifications (NotRegistered in old version and Requested entity was not found in the new version).
But if I replace the token (update ... set Token = NewToken where CompanyID = CompanyID), it will make another device (that has logged in the same company account) unable to get notifications anymore.
I'm somewhat OK with the first solution, but it will result in 90% dead (but I don't know that on the server side) \ 10% alive tokens for any CompanyID in the database in just over a month.
The idea is to check all the tokens for the given CompanyID, determine if any of them shares the same device with the recieved token and if it is, replace it. Otherwise - add new.
So this type of error is being reported on a lot of community boards over the course of the last year with no acceptable answer we could find. We have just started our journey integrating with Google Home and created a Home Automation Action and we are getting a similar error …
{
insertId: "10wvnj2fyb1thy"
logName: "projects/bitdog-home-f69bd/logs/actions.googleapis.com%2Factions"
Show matching entries
Hide matching entries
Add field to summary line
receiveTimestamp: "2018-12-06T13:28:13.939975519Z"
resource: {
labels: {
action_id: "SMART_HOME_SYNC"
project_id: "bitdog-home-f69bd"
version_id: ""
}
type: "assistant_action"
}
severity: "ERROR"
textPayload: "SYNC: Request ID 742344561631232315 failed with code: OPEN_AUTH_FAILURE"
timestamp: "2018-12-06T13:28:13.931998358Z"
}
This shows on Google Home app as "Couldn't update the setting, check your connection"
The OAuth service logs show a successful account linking and a successful refresh_token request. Google does not attempt a SYNC call to the Action handler from what we can tell.
We have other systems using the OAuth server and they are working well and we are little lost on how to proceed to debug this issue. We created a support ticket today but I don't feel confident that we will get meaningful help.
We have also tried using the Google Home app on Android and iOS. We have tried changing the default browser from Chrome to Firefox. Nothing has changed the outcome. We also made sure that our access_token was in JWT format to see if google was sensitive to token size or format and nothing worked. We even made sure that the Google Home app user matched the user logged into the browser.
Help!
I did get it working. It was already working with an Amazon Echo Skill but it seems that Google's implementation (OpenAuth) is a bit more strict. I changed my access_token from a proprietary encrypted token format to a legit signed JWT token. I also removed expires_in from the response and it started working, not sure if it was the access_token JWT token format or removal of expires_in. I'm happy I can move on. If I get a chance, I will test to see which change made it work and comment here again.
Thank you.
To anyone with this problem–
I had to take multiple steps to resolve this issue, which are not clearly outlined in any documentation.
As per Google support:
Please adjust your account linking implementation from implicit to auth code flow then perform test again.
On the documentation for OAuth account linking, it says there are two methods of authentication: implicit and auth code. Apparently, only the auth code flow works for smart home.
I am using the Actions on Google Node.js library. While poking through the documentation, I found that:
[The SYNC request fulfillment] should return a valid response or a Promise that resolves to valid response.
The problem is that I was doing a database operation (which took time), so I couldn't simply return a value when it was ready; I had to return a Promise insead, then fulfill that promise later.
Hopefully this is helpful to anyone stuck on this reoccurring issue! Basically, check your auth flow and make SYNC is returning a valid JS object on time.
I was facing the same issue from last 2 weeks and was wonder when saw it is a 3 steps problem.
Check your SYNC intent is properly parsed
Incorrect Response Structure (Verify here-Smart Home SYNC Data Validator)
Device Response time-out should be less than 5 sec.
You can check Link
My problem started when I connected by Sonoff Bridge.
So I got it working by removing my 'Sonoff Bridge' and connecting it to Google Home. (All mu light are now working). Added the Bridge again to Sonoff and using IFTTT to connect to my Bridge
I am using the Google Cloud Messaging services described at https://developers.google.com/instance-id/reference/server but I am getting a HTTP response status of 400 and this response text:
{"error":"InvalidTokenVersion"}
At the time I write this, that exact error code has zero results on Google! Has anyone else encountered it? I could understand "InvalidToken" but it is the "Version" bit which is confusing me.
I'd like to see a nice list of all the possible error codes for the https://iid.googleapis.com/iid/info/ and https://iid.googleapis.com/iid/v1/*/rel/topics/* services, if you know where that is?!
All the GCM pages say at present is...
HTTP status 400 (Bad request) - request parameters are missing or invalid. Check error messages for detailed information.
Background information:
I am using a registration token from an Android device which still shows a log of successful notifications in the GCM Diagnostics (part of Google Play Developer Console). So surely the token cannot be wrong?
If I try a token value of "bum" I get error "InvalidToken" instead.
However, trying to send a new notification with https://gcm-http.googleapis.com/gcm/send results in the "InvalidRegistration" error, so I guess something has gone screwy.
I'd like to claim that I've changed nothing recently, but something to do with SSL on the server might have expired I suppose.
The token you are providing is regId not instanceId.token. Follow the documentation:
https://developers.google.com/cloud-messaging/android/client.
see examples here.
https://github.com/googlesamples/google-services/tree/master/android/gcm/app/src/main/java/gcm/play/android/samples/com/gcmquickstart
I'm using fusion tables with an android app that I'm developing in AppInventor, and I had a question about the SQL Query for updating a row.
Now, before I ask the question, I will let you know that I would have included some screenshots of my blocks-editor code, but my boss told me I had to keep the app 100% closed source, so I can't provide any. Hopefully I'm not being too vague.
Anyways, I set a FusionTablesControl query using the "make text" block and the Google API UPDATE query, but when I send the query on my test device (Samsung Galaxy Player 5), the overlaying "Fusion Tables" load screen pops up for only a split second (it normally shows for 2 or 3 seconds). When I check the tables, there has been no change.
I think syntax is still a potential problem because when I typed the encoded URL into google chrome's address bar, it still didn't update the table. Here is the basic syntax of what I typed into the address bar.
https://www.googleapis.com/fusiontables/v1/query?sql=UPDATE%20tableID%20SET%20(Column1%3Ddata1%2C%20Column2%3Ddata2%2C%20Column3%3Ddata3%2C%20Column4%3Ddata4)%20WHERE%20ROWID%20%3D%20%27rowID%27
The decoded URL after the "sql=" part is:
UPDATE tableID SET (Column1=data1, Column2=data2, Column3=data3, Column4=data4) WHERE ROWID = 'rowID'
Any help would be appreciated.
Also, is it possible to set Google's API response to CSV instead of JSON?
Thanks,
~T16626
This does not work like that, because you did not use authentication. More about that see here:
Identifying your application and authorizing requests
Every request your application sends to the Fusion Tables API needs to
identify your application to Google. There are two ways to identify
your application: using an OAuth 2.0 token (which also authorizes the
request) and/or using the application's API key. Here's how to
determine which of those options to use:
If the request requires authorization (such as a request for an
individual's private data), then the application must provide an OAuth
2.0 token with the request. The application may also provide the API key, but it doesn't have to. If the request doesn't require
authorization (such as a request for public data), then the
application must provide either the API key or an OAuth 2.0 token, or
both—whatever option is most convenient for you.
To access a fusion table with App Inventor, you have 2 possibilities:
use the built-in fusiontable control blocks, how to set up everything for App Inventor please see the Pizza Party tutorial
use the web component with authentication, for details see here
Im developing push notification server that works with google's C2DM service.
When I get "Update-Client-Auth" in the response header , I replace the previous token , for use on the next push notification.
When I send notification right after I got new token , it fails -
with the response - "InvalidRegistration"
My questions are ?
How to avoid this ? Should I wait before I use the new token ?
When do I need to start using the new token ? is the expiration date included on header should be used ?
I havent found this phenomenon mentioned anywhere.
thanks for any advice.
I don't think the problem is with your Auth. token.
"InvalidRegistration" means that the Registration token of the device to which you're sending the C2DM Message is invalid. You should make sure that the device sends you an updated Registration Id/token if it changes (apparently it can).
Clear your server cache/DB and start again by getting the device to re-register with Google and then send the registration token to your server and see what happens.
Of course, I'm guessing you don't have lots of registrations in your DB, if you're still in development...
Regards,
Mark