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.