Ricardo Acras Ricardo Acras - 26 days ago 5x
Android Question

Push Notifications to Ionic app using GCM

I'm writing an Ionic app and trying to make Push Notifications to work.

I'm using the phonegap-plugin-push plugin to do so.

On the "$ionicPlatform.ready" event I get the device token

var push = PushNotification.init({
android: {
senderID: "36112019308"

push.on('registration', function(data) {
window.localStorage.setItem('tkn', data.registrationId );

well, here I get the registration id. Now, when I try to follow the steps described here, with a curl command like the following

curl --header "Authorization: key={KEY_GOT_ON_GOOGLE_CONSOLE}" --header "Content-Type: application/json" https://android.googleapis.com/gcm/send -d "{\"registration_ids\":[\"THE_REGISTRATION_ID_GOT_ON_DEVICE"]}"

I get the error:


Well, I am confident that the key and the registration id are correct because if I change the key I get unauthorized error and if I change the registration id I get InvalidRegistration error

What could be that I am doing wrong?

Aditional Info

  • Testing with debug build


I got it. The error message was really misleading.

The full token returned after registration was something like this:


For some reason I was only using what came after the ":" and in this case the error was MismatchSenderId. I was convinced that the registration was ok because if I changed anything on the string it returned InvalidRegistration. But in fact the whole string should be used, including the part before the ":"