The odd thing is that notifications were working before. So I'm not sure what happened. I tried reinstalling my app to the device, but nothing changed.
{"multicast_id":xxxxxxxxxxxxxxxxxxx,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"MismatchSenderId"}]}
Because this was working at one point, I know I am using the correct keys. I even triple checked based on other SOF threads I came across. What could be the potential problem now? I've looked around for a few days now and I'm still at a loss..
** EDIT **
Here's the POST info when a message is sent out from my server.
Headers
Array
(
[0] => Authorization: key=xxxxxxx-key-for-browser-apps-from-google-apis-console-xxxxxxx
[1] => Content-Type: application/json
)
Fields
Array
(
[registration_ids] => Array
(
[0] => xxxxxxxxx-big-old-id-from-the-device-xxxxxxxx
[data] => Array
(
[message] => hello
)
)
Also
I am using the key associated with Key for browser apps (with referers).
Apparently, when you recompile your app it will sometimes throw off the device id generation to where it won't match a previous id.
What I have to do is a COMPLETE uninstall of the app on my phone and recompile the app again (via eclipse). This seems quite pathetic, but it's the closest to a workable solution I have at the moment..
I think it must be something to do with the way you have set up API access for your project in the Google APIs console, in particular the 'allowed referers'. As the dev docs say
Mismatched Sender A registration ID is tied to a certain group of
senders. When an application registers for GCM usage, it must specify
which senders are allowed to send messages. Make sure you're using one
of those when trying to send messages to the device. If you switch to
a different sender, the existing registration IDs won't work. Happens
when error code is MismatchSenderId.
My project is set up to allow any referer like:
Key for browser apps (with referers)
API key: my secret
Referers: Any referer allowed
Perhaps you have restricted it to a certain IP range, and now you are trying to send the message from outside that range
you did not use right device token, that's why you got the error.
So, please get the new device token (Android mobile's token) and use it
curl -X POST \
-H "Authorization: key= write here api_key" \
-H "Content-Type: application/json" \
-d '{"registration_ids": ["write here reg_id generated by gcm"],
"data": { "message": "Manual push notification from Rajkumar"},
"priority": "high"
}' \
https://android.googleapis.com/gcm/send
MismatchSenderId because with in same device you have logged with different keys. to solve this problem uninstall app and run it againg and update the registration key. and then run the CURL script in your teminal which i post above it will give success message and you will get notification to your device
Related
I found at https://developers.google.com/instance-id/reference/server#get_information_about_app_instances the following example GET request:
https://iid.googleapis.com/iid/info/nKctODamlM4:CKrh_PC8kIb7O...clJONHoA?details=trueAuthorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA
The key in that example is: AIzaSyZ-1u...0GBYzPu7Udno5aA. Where can I find my key, the one that I should use in my GET request? I am trying to find it at https://console.developers.google.com/apis/credentials, and this is what I see:
I tried using all of the four keys that you see in the image above, and I always receive this message from the browser:
{"error":"MissingAuthorization"}
Does this error refer to the key being wrong, or to something else? Am I looking in the right place for the key? Thank you.
EDIT 1: I was looking at the question at How to check how many topics has been subscribed?, and I also tried using the keys that I found in my Firebase Console, under the "Cloud Messaing" tab. This is what I see:
I tried the GET request using those keys in the image above as well and I still see the same error: {"error":"MissingAuthorization"}.
EDIT 2: I am using this from the command line:
C:\curl>curl -k https://iid.googleapis.com/iid/info/nKctODamlM4:CKrh_PC8kIb7O...clJONHoA?details=trueAuthorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA
{"error":"MissingAuthorization"}
C:\curl>
Notice how I simply copied/pasted what I found at https://developers.google.com/instance-id/reference/server#get_information_about_app_instances under the "Example GET request" heading. I am not even attempting to use my own keys and I see the same error: {"error":"MissingAuthorization"}. Does it mean the problem is with the key I am using? Is not it the one I see in the Firebase Console?
Based on the instructions at https://developers.google.com/instance-id/reference/server, under the heading "Get information about app instances", it shows that it is necessary to provide the Authorization: key=YOUR_API_KEY, which is set in the header. See at https://android.jlelse.eu/firebase-push-notification-using-curl-command-devoid-backend-e63795d282c4 an example of how to provide a parameter in the header.
Concerning the Authorization: key=YOUR_API_KEY that has to be used, it is the key that appears in the "EDIT 1" section of this question. I used the Server key, not the Legacy server key, and it worked for me.
https://developers.google.com/instance-id/reference/server shows this end point: https://iid.googleapis.com/iid/info/IID_TOKEN. But IID_TOKEN must be replaced with the instance ID token which corresponds to the instance of the app that was installed on a device. In my case, I found it by printing the instance ID or token of the device, using the following code in the first activity of my Android app:
Log.d("The token of device: ", FirebaseInstanceId.getInstance().getToken());
In the log of the Android monitor, I found the IID_TOKEN that I needed:
D/The token of device:: f35EFw4bsef:QWE34bFm56ZuQLWYSDDgPlkf4a88Lu6Gp4DoXVDJ5dRIlsdDncq0UdNnlDi7wxbbut6YX7Z1kwgyS3bzk_Zrl-1doHCf9XFdOXTThNzo4sDFEWqQjHKfNa3uH2Js4Flbf_CnRkD2Mftr
Finally, I used cURL from the command prompt, and you can see how I obtained results correctly:
C:\curl>curl -X GET -k --header "Authorization: key=AAAAJ5XteYp:DKE32aIdFalyFXku6A-eR_wHL6ZBUFxfyPtcrm3wwF2l-nPEv_vAeYqo3NJzaIKKcSSow6gqoAwf3cBEm8QWYbF6w-asW0SX0RmHZftQglwmo_ziwrk8wFcGp1_DOQ1PLFFgP4BFWXAD" "https://iid.googleapis.com/iid/info/f35EFw4bsef:QWE34bFm56ZuQLWYSDDgPlkf4a88Lu6Gp4DoXVDJ5dRIlsdDncq0UdNnlDi7wxbbut6YX7Z1kwgyS3bzk_Zrl-1doHCf9XFdOXTThNzo4sDFEWqQjHKfNa3uH2Js4Flbf_CnRkD2Mftr
{"applicationVersion":"22","attestStatus":"NOT_ROOTED","application":"com.[myapp]","scope":"*","authorizedEntity":"232255245625","appSigner":"3d34g3fs3443292d825f21da4fdd5b34a56f2a3h","platform":"ANDROID"}
C:\curl>
Note: In the code above I have changed the values of things such as tokens and keys for privacy purposes, but you need to use your values and everything should work.
I have a mobile app (both iOS and Android) created for an online shop. This particular version of the app is for the sellers only. There is a section in it that function as a helpdesk. Basically buyers can open tickets, send messages to sellers etc. So what I want to do is every time when a buyer does that, the seller should receive a push notification on his device.
The database that keeps records of buyers, sellers and everything else runs on a separate server. I can have some sort of a cron job to periodically check for new cases opened by buyers. I'm hoping to use Parse to handle push notifications.
Now where I'm a stuck at is how to associate my database server with Parse.
My current plan is something like this.
The app is launched and the seller is logged in for the first time. Parse SDK registers the device with its servers. Alongside this, using a separate web service, I was hoping to save the unique ID generated by Parse (Upon research, I found the suitable unique ID is called Installation ID) and the logged in seller's ID in my database as well.
When the cron job finds an open case, it retrieves the seller's ID that it should go to. Along with it, that Installation ID.
My server sends out a HTTP request to post a push notification to the device with that Installation ID using Parse's REST API.
One issue. They haven't specified a way to pass an Installation ID in their docs.
I want to know if this is possible? Or if there is a better way to go about this?
Pretty sure that is possible. First you can get the installationId via the PFInstallation:
PFInstallation.currentInstallation().installationId // swift
or
[PFInstallation currentInstallation].installationId // Objective-C
Dont know about android but probably similar
ParseInstallation.getCurrentInstallation().getInstallationId() // Java
https://parse.com/docs/osx/api/Classes/PFInstallation.html https://parse.com/docs/android/api/com/parse/ParseInstallation.html
Send the push
And then you actually have to send the push: Take a look at the Parse REST guide under "using advanced targeting".
You can use a curl query like the following:
curl -X POST -H "X-Parse-Application-Id: %appId%" -H "X-Parse-REST-API-Key: %api key%" -H "Content-Type: application/json" -d '{ "where": { "installationId": "%installationId%" }, "data": { "alert": "The Giants scored a run! The score is now 2-2." } }' https://api.parse.com/1/push
The important part here is the { "where": { "installationId": "%installationId%" } which sends the push message to only the Installations that match the query - exactly the one installation with the given id.
I just tried and got a push message only on specific device :)
I read basic example for implementing google gcm. I developed small client side android application which successfully gives me registration id from gcm server.. now on server side I am using Ruby on rails hence we use this gem for implementing server side of gcm https://github.com/dondeng/gcm_on_rails. I pass my registration id to to my server.
I successfully ran these commands
device = Gcm::Device.create(:registration_id => "XXXXXXXXXXXXXXXXXXXXXX")
notification = Gcm::Notification.new
notification.device = device
notification.collapse_key = "updates_available"
notification.delay_while_idle = true
notification.data = {:registration_ids => ["RegistrationID"], :data => {:message_text => "Get on cloud nine"}}
notification.save
used to deliver notifications:
$ rake gcm:notifications:deliver
my rake command running without any error. But after completion of all these tasks my device not receiving any message.. I don't know whats going on in background. How to confirm that sent message properly receive by device.. Need Help... Thank you....
Debugging GCM messages can be cumbersome and difficult.
One possible reason is a wrong API key for GCM, which must be defined in the configuration files. If you use the wrong API key, then you might get a success response from the server {:code=>200, :message=>nil}, although no message has been sent. In this case go to the Google API Console and look up the right key.
Another possible reason is a wrong REGISTRATION_ID for the device. if the REGISTRATION_ID is not correct you may get an NotRegistered or InvalidRegistration error, which is not always recognized by the gcm_on_rails plugin (at the moment). Use the following curl command to debug the API through the console (insert your API_KEY and the REGISTRATION_ID of the device).
curl --header "Authorization: key=API_KEY" \
--header Content-Type:"application/json" \
https://android.googleapis.com/gcm/send \
-d "{\"registration_ids\":[\"REGISTRATION_ID\"],
\"data\":{\"message_text\":\"Test, Test\"}}"
A successful / unsuccessful attempt to call the Gcm API should look like this:
{"multicast_id":7961..,"success":1,"failure":0,"canonical_ids":1,
"results":[{"registration_id":"..","message_id":"0:.."}]}
{"multicast_id":7961..,"success":0,"failure":1,"canonical_ids":0,
"results":[{"error":"NotRegistered"}]}
Finally another reason is an invalid key in the day: do not use a reserved word like message_type as a key in the data hash. It will return a status code 200, but it will not deliver any notification. message_type is one of the advanced options (took me more than an hour to find that out).
If you have no error on server-side, maybe you are not handling correctly the event in your Android App.
Follow this guidelines: http://developer.android.com/guide/google/gcm/gs.html#android-app, and write logs for debug.
I'm trying to create a push service for my Android app, and I follow Google GCM's documentation and example for this matter:
I can register/unregister my Android app. From my server side, I can see that I have one subscription registered, but when I try to send a message from server to my Android app I always get following error:
Error sending message to device #0: MismatchSenderId
For my Android app, I use SENDER_ID = 200000000001.
And for my server side as Google says I use API_KEY = AIzxxxxxxxxxxxxxxxxXxxXxxXxxxXXXXXxxxxs
I followed this document:
http://developer.android.com/guide/google/gcm/demo.html
I've enabled GCM in my Google API panel too, yet I'll get that annoying error message.
How can I fix this problem?
Did your server use the new registration ID returned by the GCM server to your app? I had this problem, if trying to send a message to registration IDs that are given out by the old C2DM server.
And also 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.
And make sure the API Key belongs to 'Key for server apps (with IP locking)'
Mismatch happens when you don't use the numeric ID. Project ID IS NOT SENDER ID!! It took me 9 hours to figure this out. For all the confusion created by google, check the following link to get numeric id.
https://console.cloud.google.com
instead of
https://console.developers.google.com
Hope it helps!!
Update:-
Things have changed again. Now the sender id is with firebase.
Go to https://console.firebase.google.com and select your project. Under settings -> cloud messaging, you can find the sender id.
And it works!
Please run below script in your terminal
curl -X POST \
-H "Authorization: key= write here api_key" \
-H "Content-Type: application/json" \
-d '{
"registration_ids": [
"write here reg_id generated by gcm"
],
"data": {
"message": "Manual push notification from Rajkumar"
},
"priority": "high"
}' \
https://android.googleapis.com/gcm/send
it will give the message if it is succeeded or failed
I encountered the same issue recently and I tried different values for "gcm_sender_id" based on the project ID. However, the "gcm_sender_id" value must be set to the "Project Number".
You can find this value under: Menu > IAM & Admin > Settings.
See screenshot: GCM Project Number
This happens when the Server key and Sender ID parameters HTTP request do not match each other. Basically both server ID and Server key must belong to the same firebase project. Please refer to the below image. In case of mixing these parameters from deferent Firebase projects will cause error MismatchSenderId
InstanceID.getInstance(getApplicationContext()).getToken(authorizedEntity,scope)
authorizedEntity is the project number of the server
Your android app needs to correct 12-digit number id (aka GCM Project Number). If this 12-digit number is incorrect, then you will also get this error.
This 12-digit number is found in your Google Play Console under your specific app, 'Service & API' -> 'LINKED SENDER IDS'
Check google-services.json file in app folder of your Android project. Generate a new one from Firebase console if you are unsure. I got this error in two cases.
I used a test Firebase project with test application (that contained right google-services.json file). Then I tried to send push notification to another application and got this error ('"error": "MismatchSenderId"'). I understood that the second application was bound to another Firebase project with different google-services.json. Because server keys are different, the request should be rewritten.
I changed google-services.json in the application, because I wanted to replace test Firebase project with an actual. I generated right google-services.json file, changed request, but kept receiving this error. On the next day it fixed itself. I suspect Firebase doesn't update synchronously.
To get a server key for the request, open https://console.firebase.google.com and select an appropriate project.
Then paste it in the request.
With the deprecation of GCM and removal of its APIs, it appears that you could see MismatchSenderId if you try to use GCM after May 29, 2019. See the Google GCM and FCM FAQ for more details.
Use sender ID & API Key generated here: http://developers.google.com instead (browse for Google Cloud Messaging first and follow the instruction).
If use for native Android, check your AndroidMaifest.xml file:
<meta-data
android:name="onesignal_google_project_number"
android:value="str:1234567890" />
<!-- its is correct. -->
instead
<meta-data
android:name="onesignal_google_project_number"
android:value="#string/google_project_number" />
Hope it helps!!
I am having trouble testing out push notifications using the C2DM service.
I am using Lars' example until "3.4. Register your application" to set up my android test project. I successfully get the Registration ID from the device.
Then I successfully get the Auth token via my server using the following curl:
curl https://www.google.com/accounts/ClientLogin -d Email=theEmailYouWhitelisted -d Passwd=pass****word -d accountType=HOSTED_OR_GOOGLE -d source=Google-cURL-Example -d service=ac2dm
So now I have the two main components to push. So for the purpose of testing I issue another curl to send a message (I am going to implement the auth token generation, and sending of message in php once I get it functional).
I use:
curl --header "Authorization: GoogleLogin auth=**authFromRegistrationAbove**" "https://android.apis.google.com/c2dm/send" -d registration_id=**phoneRegistrationId(reciever)** -d "data.message=HelloPush" -d collapse_key=something -k
Response:
Error=NotRegistered
This is where I am, and confused. I successfully got my Auth Token using my white listed email / pw registered and accepted into the C2DM program via my client server. Then compiled Lars' project to generate my devices registration id, but once they are used together I get the not registered error above, and no push notification.
Ideas? Comment if you need anymore information and I'll update the post. Thanks.
If you follow me example you should maintain your registered C2DM user (Email address) in the Text Field in RegisterActivity.This must be the same as in the CURL thing. Also make sure you copy the authentication string correctly.
Did you see check this previous question already? This problem is also frequently discussed on the android-c2dm mailing list. Here's a search for NotRegistered.
A common problem is that you are not using the same sender ID on the application as the one you used to generate the auth token. Note that in the C2DM signup form, there are two email addresses you provide: one is just to notify you when you're accepted, and the other is the "Role Account". The latter is also known as the sender ID and is what must be used on the phone application and for the account used to generate the auth token.