1

I'm trying to implement push notifications into my Cordova application and have been following some tutorials.
I'm using this piece of code to send the notification to the app but I get a MismatchSenderID error for some reason. I checked and regenerated the access key multiple times, the GCM ID is what I get from the app so it should work.
Why could that be?

<?php
// API access key from Google API's Console
define( 'API_ACCESS_KEY', 'xx' );
$registrationIds = 'xx';
// prep the bundle
$msg = array
(
    'message'   => 'here is a message. message',
    'title'     => 'This is a title. title',
    'subtitle'  => 'This is a subtitle. subtitle',
    'tickerText'    => 'Ticker text here...Ticker text here...Ticker text here',
    'vibrate'   => 1,
    'sound'     => 1,
    'largeIcon' => 'large_icon',
    'smallIcon' => 'small_icon'
);
$fields = array
(
    'registration_ids'  => array($registrationIds),
    'data'          => $msg
);

$headers = array
(
    'Authorization: key=' . API_ACCESS_KEY,
    'Content-Type: application/json'
);

$ch = curl_init();
curl_setopt( $ch,CURLOPT_URL, 'https://android.googleapis.com/gcm/send' );
curl_setopt( $ch,CURLOPT_POST, true );
curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers );
curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false );
curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $fields ) );
$result = curl_exec($ch );
curl_close( $ch );
echo $result;
?>

--EDIT: more info

I had already tried the solutions given in the threads linked below by fire, however they don't seem to work, or I'm doing something wrong since the url format and layout of Google Console changed since then to something like this: https://i.stack.imgur.com/0oLrg.jpg I did try reinstalling phonegap to obtain a different registration id and tried both of those IDs, both the one in the URL and the one below. I can succesfully send push notifications via terminal, so the registration ID must be right.

Hissvard
  • 488
  • 7
  • 24

1 Answers1

0

Based from this blog, you'll be getting a MismatchSenderID error if the Sender ID and API_KEY doesn't match.

As stated here, look at the URL of your project in the Google API Console: https://code.google.com/apis/console/#project:xxxxxxxxxxx wherein the xxxxxxxxx is the project ID, which is the sender ID. Make sure the API Key belongs to 'Key for server apps (with IP locking)'.

MismatchSenderId also occurs when you have logged with different keys within same device. Try to uninstall app and run it again. Then update the registration key and then run the CURL script below 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 message if it succeeded or failed.

Check these related threads:

Hope this helps!

Community
  • 1
  • 1
abielita
  • 13,147
  • 2
  • 17
  • 59
  • Thanks for your answer although I'd already tried those solutions. I'm gonna edit the question instead of commenting here for better readability. – Hissvard Aug 08 '16 at 09:23