Answer the question
In order to leave comments, you need to log in
Successfully sending push notifications, but not coming to the browser, how to fix it?
Good day, I want to add notifications to my corporate website.
I'm testing this code, everything seems to be fine, but notifications are not displayed in the browser, although everything has been sent.
Maybe there are some ideas?
$YOUR_API_KEY = '111111111111111111111111111'; // Server key
$YOUR_TOKEN_ID = '11111111111111111111111111111';
$header = array();
$header[] = 'Content-type: application/json';
$header[] = 'Authorization: key=' . $YOUR_API_KEY;
$payload = [
'to' => $YOUR_TOKEN_ID,
'notification' => [
"title" => "Background Message Title",
"body" => "Background message body",
"click_action" => "https://dummypage.com"
]
];
$crl = curl_init();
curl_setopt($crl, CURLOPT_HTTPHEADER, $header);
curl_setopt($crl, CURLOPT_POST, true);
curl_setopt($crl, CURLOPT_URL, 'https://fcm.googleapis.com/fcm/send');
curl_setopt($crl, CURLOPT_POSTFIELDS, json_encode($payload));
curl_setopt($crl, CURLOPT_RETURNTRANSFER, true);
$rest = curl_exec($crl);
if ($rest === false) {
return curl_error($crl);
}
curl_close($crl);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question