-
-
Save prime31/5675017 to your computer and use it in GitHub Desktop.
<?php | |
// API access key from Google API's Console | |
define( 'API_ACCESS_KEY', 'YOUR-API-ACCESS-KEY-GOES-HERE' ); | |
$registrationIds = array( $_GET['id'] ); | |
// prep the bundle | |
$msg = array | |
( | |
'message' => 'here is a message. message', | |
'title' => 'This is a title. title', | |
'subtitle' => 'This is a subtitle. subtitle', | |
'tickerText' => 'Ticker text here...Ticker text here...Ticker text here', | |
'vibrate' => 1, | |
'sound' => 1, | |
'largeIcon' => 'large_icon', | |
'smallIcon' => 'small_icon' | |
); | |
$fields = array | |
( | |
'registration_ids' => $registrationIds, | |
'data' => $msg | |
); | |
$headers = array | |
( | |
'Authorization: key=' . API_ACCESS_KEY, | |
'Content-Type: application/json' | |
); | |
$ch = curl_init(); | |
curl_setopt( $ch,CURLOPT_URL, 'https://android.googleapis.com/gcm/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; |
great function,
i dont recive notification when the app is closed.. do you know what i need to do????
you should use custom json(data) to send fcm
Hello,
The code was working very well, then from nowhere am receiving this error: "Error=DeprecatedEndpoint". And the notification is not being sent. Is there a fix for this?
Same problem for me
'https://android.googleapis.com/gcm/send' is outdated, use 'https://fcm.googleapis.com/fcm/send' instead. (worked for me this morning)
Sample to check with new URL:
curl "https://fcm.googleapis.com/fcm/send" -X POST -H "Authorization: key=MY_AUTH_KEY" -H "Content-Type: application/json" -d '{"registration_ids":["MY_DEVICE_REGISTRATION_ID"],"priority": "high","data": {"vibrate":"false", "changes":"state:off", "source":"gcmsend_fhem", "type":"notify", "deviceName":"TestLampe", "gcmDeviceName":"andFHEMUpdater"}}'
Answer must be anything like this:
{"multicast_id":123,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:123"}]}
Thank you @acaliebe!!! Its back on.
Hello @acaliebe,
It works fine for me, It successfully gives a Success message but actual notification is not getting. Dont know why this happened. Can you please help me, I am eagerly waiting for your reply. Thanks.
Thank you @acaliebe
{"multicast_id":4314312645771955637,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"InvalidRegistration"}]}
why no one is giving the solution of this error? when you are sharing your code you should make sure that it will execute successfully
How to find THE_DEVICE_REGISTRATION_ID ? please, help me.
How to find THE_DEVICE_REGISTRATION_ID ? please, help me.
@wirakw it got from client(android) get regId(), just like generated string
myabe like this :
https://gist.github.com/prime31/5675017#gistcomment-1785186
hi everybody,
i was trying to insert a picture to the message, but failed in any way, here is my code:
$msg = array
(
'body' => "Wir wünschen all unseren Kunden, Freunden und Familien ein frohes Osterfest und freuen uns Euch bald wieder in einem unserer Studios begrüßen zu dürfen!",
'title' => "Nachricht aus dem MoveCenter",
'vibrate' => 1,
'sound' => 1,
'image' => 'https://www.fentler.com/move/app1170/imagesApp/osterhase.jpg',
);
$fields = array
(
'registration_ids' => $registrationIds,
'notification' => $msg
);
$headers = array
(
'Authorization: key=' . 'MY KEY HERE',
'Content-Type: application/json'
);
all works fine, but no image is displayed on adroid
Replace 'data' in line number 25 with 'notification' to get the notification messages displayed on the notification.
Replace 'data' in line number 25 with 'notification' to get the notification messages displayed on the notification.
Please how to get the registration ID ?
Replace 'data' in line number 25 with 'notification' to get the notification messages displayed on the notification.
Please how to get the registration ID ?
Follow this video from FCM:
https://youtu.be/BsCBCudx58g
Replace 'data' in line number 25 with 'notification' to get the notification messages displayed on the notification.
Please how to get the registration ID ?
Follow this video from FCM:
https://youtu.be/BsCBCudx58g
Thanks!! it helped me alot!!
Thanks!! it helped me alot!!
You are welcome.
notification
Thank you man!!! It made worthy of my 2 days work.
Thank You!! It really helped out....
Is it possible to add a sound with the notification?
how to send to multiple devices at once with their tokens
It is not working in 2022
Yes it is.
…
On Thu 17 Sep, 2020, 10:04 PM ImtiazXYZ, @.> wrote: @.* commented on this gist. ------------------------------ Is it possible to add a sound with the notification? — You are receiving this because you commented. Reply to this email directly, view it on GitHub https://gist.github.com/5675017#gistcomment-3457708, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGAEPD757MJT7ZE52AADVA3SGI3CRANCNFSM4HHJLYCA .
yes, but HOWWWWWWWWW
@DavidAlejandroM please share code for your index.html, do we need to activate/call any function? I keep getting "InvalidRegistrationID"