Send notification with Firebase API

aksoyhlc

New Member
Hello there. I would like to send notification using Firebase API. My APIs are ready, but I can't send notifications with the API because I don't know the topic part of 'to' => "/topics/xxxxx" in this field. The notification appears to have been sent, but users are not notified. What did you write to the topic section when writing the application?

My code:

PHP:
define('API_ACCESS_KEY','xxxxxxxxxxxxxxxxxxxxxxx');
$fcmUrl = 'https://fcm.googleapis.com/fcm/send';
$notification = [
'title' =>'xxxxxxxxxxxxxxxx',
'body' => 'yyyyyyyyyyyyyyy.'
];
$extraNotificationData = ["message" => $notification,"moredata" =>'dd'];
$fcmNotification = [
"content-available"=>"1",
'to' => "/topics/All", //single token
'notification' => $notification,
'data' => $extraNotificationData
];
$headers = [
'Authorization: key=' . API_ACCESS_KEY,
'Content-Type: application/json'
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$fcmUrl);
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($fcmNotification));
$result = curl_exec($ch);
curl_close($ch);
echo $result;
returned date:

Code:
{"message_id":4709853598141.......}
 
Top