Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP GCM error message MismatchSenderId

I am facing the problem with GCM push notification. I am getting the following error.

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

Following is the code. Any help would be really appreciated. Thanks in Advance.

public function gcmPush() 
{
    $regId = "APA91bHFcgOssQZEqtdUk3EC1ojwC5-LVG3NPV2bMqKyC9rPymR6StmAbz-N7Ss8fnvruZhWWNrR3lmBqpjQItlu00AKHPbltBclUJF-EfC5qG4CF2xiuYYC0NCf8u5rbiYFk8ARhIT4lY2AEPWzGpl1OtTvQEC0gA"; 
    $registatoin_ids = array($regId); 
    $message = array("msg" => 12345); 

    $this->send_notification($registatoin_ids, $message);
}

public function send_notification($registatoin_ids, $message) 
{
  // Set POST variables
  $url = 'https://android.googleapis.com/gcm/send';         
  define('GOOGLE_API_KEY', 'AIzaSyBavsIgQKo1Nf9wKZ5o_fGvE_6MI52LFR0');
  $fields = array(
    'registration_ids' => $registatoin_ids,
    'data' => $message,
  );
  $headers = array(
   'Authorization: key=' . GOOGLE_API_KEY,
   'Content-Type: application/json'
  );

  // Open connection
  $ch = curl_init();

  // Set the url, number of POST vars, POST data
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_POST, true);
  curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

  // Disabling SSL Certificate support temporarly
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));

  // Execute post
  $result = curl_exec($ch)
  if ($result === FALSE) {
      die('Curl failed: ' . curl_error($ch));
  }

  // Close connection
  curl_close($ch);
  echo $result;
}
like image 295
user2509333 Avatar asked Jun 24 '13 11:06

user2509333


1 Answers

"MismatchSenderId" is the obvious problem that we are getting nowadays.

Here are the possible cases that cause this problem.

Case 1: Mismatching Sender ID -> Please check the Project number which you are using. If it's is correct or not.

Case 2: Wrong API Key -> Please be sure that you are using the same API_Key or not. And in most of the cases, we need to generate Server_Key instead of Android_Key.

Case 3: Wrong Device's ID -> Most of the time the problem is due to the wrong Device ID(Registration ID generated by GCM).

Please be ensure that that Whenever you generate new API key, the device id's of your device gets changed. Then it will take almost 5 five minutes to get an effect.

Note : Your device id is bound with the API KEY.

So....

--New Key created.

--GCM for Android Turned "on" in Google Dev. Console.

--Device registered with backend fine (Android Project is doing its job). Device key on the server.

--Send to device. Fail! The same message is returned from GCM everytime.

To Recap. This is NOT an Android Studio, Android OS, or Device issue. The GCM servers are not even trying to send the message to the device. My server sends to GCM, it returns the message...

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

to the server. As far as I can tell this means the Device's ID (the one returned to the device when it registered for a push, and the one saved on the backend (in the control panel) does not match, or is somehow not associated with the API Key used when sending the message.

Sending, of course, starts on my server, goes to GCM, then goes to the device.

This is what's not happening. The message goes from my server to GCM and back to my server - with the error.

Super frustrating as all of you can imagine - we've all been through this nightmarish stuff before :-)

Reference : https://www.buzztouch.com/forum/thread.php?tid=C3CED924C86828C2172E924

Hope it will solve your problem.

like image 170
KishuDroid Avatar answered Oct 26 '22 15:10

KishuDroid