|#API access key from Google API's Console|
|define( 'API_ACCESS_KEY', 'YOUR-SERVER-API-ACCESS-KEY-GOES-HERE' );|
|$registrationIds = $_GET['id'];|
|#prep the bundle|
|$msg = array|
|'body' => 'Body Of Notification',|
|'title' => 'Title Of Notification',|
|'icon' => 'myicon',/*Default Icon*/|
|'sound' => 'mySound'/*Default sound*/|
|$fields = array|
|'to' => $registrationIds,|
|'notification' => $msg|
|$headers = array|
|'Authorization: key=' . API_ACCESS_KEY,|
|#Send Reponse To FireBase Server|
|$ch = curl_init();|
|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_RETURNTRANSFER, true );|
|curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false );|
|curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $fields ) );|
|$result = curl_exec($ch );|
|curl_close( $ch );|
|#Echo Result Of FireBase Server|
@MohammadaliMirhamed YOUR-SERVER-API-ACCESS-KEY-GOES-HERE is the server key right and THE_DEVICE_REGISTRATION_ID is the device token. i am using the right details but i get:
I ended up with this :
But the issue is : in the service worker push handler , i am not getting the contents set in $msg. In the console I see this :
That is the data is null. Any idea why ?
Getting the following error:
The registration id was picked up from the app. It is correct. FCM API key is also correct. Not sure where the issue is.
I am also getting below response with invalidRegistration
May I know please where I am doing wrong?
It's working fine , but when I am running this code , notification goes by service worker and title , body , icon all goes from service worker .
Help me please
Anyone know how to get the Registration ID for web? I successfully generate this token:
Is it correct that the 11111:2222222 is the Registration ID? I still get MismatchSenderID error just like the people above.
I tried other value but it gives me InvalidRegistration error.
If you are talking about Android, then I think we have the same issue. Go to Settings -> Developer Options and look for "Show notification channel warnings". I think this option is only available on Android 8. Enable it and test it again. If you see something like "failed to post notification on channel 'null', then you do have the same issue as what I have.
Android 8 have this new feature for notification which can be assigned to a channel ID.
I Google this for the entire day and tried several recommendation, but unfortunately I am still trying to find the solution to this.
New api uses this format:
Also there are changes to auth and payload. More info here: https://firebase.google.com/docs/cloud-messaging/migrate-v1