0

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:

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

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
Ricardo Acras
  • 35,784
  • 16
  • 71
  • 112

1 Answers1

0

I got it. The error message was really misleading.

The full token returned after registration was something like this:

dWWt-ohQFWg:APA91bFBgEU1aRyykLCw2lNat57WSePvbXyiLcCoHh6Tt6dkzXs5HUNl8C4wDL-BgaBrzJJc0lHH8IGQ3zACcfyQEdQmpKTJWOWshWKIH0e_RByg5zkhX0AlvFL4_0DLMzd_Hz1YKZ1g

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 ":"

Ricardo Acras
  • 35,784
  • 16
  • 71
  • 112