php - Firebase MismatchSenderID when Authorization key is my Server key -


really weird , no 1 has ever asked this.

i'm getting mismatchsenderidas error server key authorization key(server key). , on other hand, i'm getting success return result push_notification() if device's token authorization key, no notification received on device.

i'm sure token correct because i'm able send single device token in firebase (single device) console.

which leads me question, confirm issue before moving notification part

i'm pretty lost actually, since mismatchsenderid errors resolved replacing correct server key.

    <?php      require "dbconfig.php";      $sql = "select token tokendb";     $result = mysql_query($sql) or die($sql."<br/><br/>".mysql_error());     $tokens = array();      while($row = mysql_fetch_assoc($result))     {         echo $row['token']; //this shows same token compared token show in logcat(visual studio)         $tokens[] = $row["token"];        echo '<form id="form1" name="form1" method="post" action="">'.     '<p>from<br>'.     '<input type="text" size="100" maxlength="100" name="from" id="from" /><br>'.     '<p>title<br>'.     '<input type="text" size="100" maxlength="100" name="title" id="title" />'.     '<br>'.     '<input type="submit" name="send" id="send" value="send" />'.     '</form>';      }      $message = array("message" => "notification test");     $message_status = sendfcmmessage($message, $tokens);     echo $message_status;      function sendfcmmessage($message,$target){         //fcm api end-point        $url = 'https://fcm.googleapis.com/fcm/send';         $fields = array();        $fields['body'] = $message;        if(is_array($target)){         $fields['registration_ids'] = $target;        }else{         $fields['to'] = $target;        }         //header content_type api key        $headers = array(         'content-type:application/json',             'authorization:key=********'        );        //curl request route notification fcm connection server (provided google)                   $ch = curl_init();        curl_setopt($ch, curlopt_url, $url);        curl_setopt($ch, curlopt_post, true);        curl_setopt($ch, curlopt_httpheader, $headers);        curl_setopt($ch, curlopt_returntransfer, true);        curl_setopt($ch, curlopt_ssl_verifyhost, 0);        curl_setopt($ch, curlopt_ssl_verifypeer, false);        curl_setopt($ch, curlopt_postfields, json_encode($fields));        $result = curl_exec($ch);        if ($result === false) {         die('oops! fcm send error: ' . curl_error($ch));        }        curl_close($ch);        return $result;     }      ?> 

edit: short php code giving me mismatchsenderid error

  <?php $ch = curl_init("https://fcm.googleapis.com/fcm/send"); $header=array('content-type: application/json', "authorization: key=***(serverkey project)"); curl_setopt($ch, curlopt_httpheader, $header); curl_setopt( $ch,curlopt_ssl_verifypeer, false );  curl_setopt($ch, curlopt_post, 1); curl_setopt($ch, curlopt_postfields, "{ \"notification\": {    \"title\": \"test desde curl\",    \"text\": \"otra prueba\"  },    \"to\" : \"my device's token\"}");  curl_exec($ch); curl_close($ch); ?> 

update

uninstalling , reinstalling app resolved issue.

the mismatchsenderid error encountered when attempting send registration token associated different sender (project). docs:

a registration token tied group of senders. when client app registers fcm, must specify senders allowed send messages. should use 1 of sender ids when sending messages client app. if switch different sender, existing registration tokens won't work.

make sure server key using same sender project registration token associated to. can checking google-services.json file , see if sender id there matches sender id visible in firebase project using send message.

for matter of not receiving messages, it's bit unclear structure of payload code sending. try checking if structured message payload notification and/or data message payload.


Comments