It always returns it, even without printing it.
{ “name”: “projects/MY_PROJECT/messages/0:1726116770149249%9feb7b149feb7b14” }
https://firebase.google.com/docs/cloud-messaging/send-message
How can I handle this?
use GoogleAuthCredentialsServiceAccountCredentials;
use GoogleAuthHttpHandlerHttpHandlerFactory;
require 'vendor/autoload.php';
function send_fcm_notify($token, $title, $message) {
$credential = new ServiceAccountCredentials(
"https://www.googleapis.com/auth/firebase.messaging",
json_decode(file_get_contents("MY-KEY.json"), true)
);
$tokenAuth = $credential->fetchAuthToken(HttpHandlerFactory::build());
$ch = curl_init(https://fcm.googleapis.com/v1/projects/MY-PROJECT/messages:send);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'Authorization: Bearer '.$tokenAuth['access_token']
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, '{
"message": {
"token": "'.$token.'",
"notification": {
"title": "'.$title.'",
"body": "'.$message.'"
}
}
}');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "post");
curl_exec($ch);
//$response = curl_exec($ch);
curl_close($ch);
//return $response;
//echo $response;
}
The response should be printed only when intended.