I have a PHP page which i used to send notifications to the users of a mobile app i developed , this page works fine until last month , then it gave me this error
{"multicast_id":5174063503598899354,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"InvalidRegistration"}]}
i tried to generate OAUTH token using the documentation in this link https://firebase.google.com/docs/cloud-messaging/auth-server#node.js but it needs NODE.JS server and my server doesn't support Node.Js , i tried to use the Firebase Admin SDK but can't find anything. Here is the PHP code of the page
<?php
//Includes the file that contains your project's unique server key from the Firebase Console.
require_once("serverKeyInfo.php");
//Sets the serverKey variable to the googleServerKey variable in the serverKeyInfo.php script.
$serverKey = $googleServerKey;
//URL that we will send our message to for it to be processed by Firebase.
$url = "https://fcm.googleapis.com/fcm/send";
//Recipient of the message. This can be a device token (to send to an individual device)
//or a topic (to be sent to all devices subscribed to the specified topic).
$recipient = $_POST['rec'];
//Structure of our notification that will be displayed on the user's screen if the app is in the background.
$notification =array(
'title' => $_POST['title'],
'body' => $_POST['body'],
'sound' => 'default'
);
//Structure of the data that will be sent with the message but not visible to the user.
//We can however use Unity to access this data.
$dataPayload =array(
"powerLevel" => "9001",
"dataString" => "This is some string data"
);
//Full structure of message inculding target device(s), notification, and data.
$fields =array(
'to' => $recipient,
'notification' => $notification,
'data' => $dataPayload
);
//Set the appropriate headers
$headers = array(
'Authorization: key=' . $serverKey,
'Content-Type: application/json'
);
//Send the message using cURL.
$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_VERIFYPEER, false );
curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $fields ) );
$result = curl_exec($ch );
curl_close( $ch );
//Result is printed to screen.
echo $result;
?>
Can anyone send me an example o how can i do this ( I am beginner in PHP ) Thanks in advance
*Update : Also i tried to change the $url in the code to
$url = "https://fcm.googleapis.com/v1/projects/notifications-9ccdd/messages:send";
but it gives me this error
"error": { "code": 401, "message": "Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.", "status": "UNAUTHENTICATED" } Blockquote