android – Error=MissingRegistration when using FCM in PHP-ThrowExceptions

Exception or error:

I am using the following code in php to send push notification to my android device

        $fields['to'] = $to;
        $fields['notification'] = $data;

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

        $url = 'https://fcm.googleapis.com/fcm/send';

        $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, $fields);

        $result = curl_exec($ch);
        curl_close($ch);
        echo($result);

But I keep getting MissingRegistrationError
I also tried json_encode($fields), but then I get the error

{
  "multicast_id": 19351993433794134,
  "success": 0,
  "failure": 1,
  "canonical_ids": 0,
  "results": [
    {
      "error": "InvalidRegistration"
    }
  ]
}
How to solve:

Leave a Reply

Your email address will not be published. Required fields are marked *