Invalid Registration Id Fcm
When I execute the code below I get: Invalid registration token I get the token from MYSQL database. I checked that the data returned matches with the database. Everything seems
Solution 1:
Solved!
Check your length of the field in which your mobile registration token is stored in your database table. Set it above 200, because the length of the token number exceeds more than 200. The API server key field must be a legacy server key provided by the firebase cloud messaging.
my working code below!
functionsend_android_notification($registration_ids, $message) {
//print_r($registration_ids);//print_r($message);//exit;
define("GOOGLE_API_KEY", "AIzaSyDfwSXWRD5tf*******************"); //legacy server key$fields = array(
'registration_ids' => $registration_ids,
'notification' => $message, //note: body & title fileds must be specified for the message or your only get just the vibration but the notification
);
$headers = array(
'Authorization: key=' . GOOGLE_API_KEY, // FIREBASE_API_KEY_FOR_ANDROID_NOTIFICATION'Content-Type: application/json'
);
//Open connection$ch = curl_init();
//Set the url, number of POST vars, POST data
curl_setopt($ch, CURLOPT_URL, 'https://fcm.googleapis.com/fcm/send');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
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));
//echo json_encode($fields);//print_r($headers);//exit;//Execute post$result = curl_exec($ch);
if ($result === false) {
die('Curl failed:' . curl_errno($ch));
}
// Close connection
curl_close($ch);
return$result;
}
Post a Comment for "Invalid Registration Id Fcm"