Contohnya menggunakan curl
Kirim pesan ke perangkat tertentu
Untuk mengirim pesan ke perangkat tertentu, atur token registrasi untuk instance aplikasi tertentu
curl -H "Content-type: application/json" -H "Authorization:key=<Your Api key>" -X POST -d '{ "data": { "score": "5x1","time": "15:10"},"to" : "<registration token>"}' https://fcm.googleapis.com/fcm/send
Kirim pesan ke topik
di sini topiknya adalah: / topik / foo-bar
curl -H "Content-type: application/json" -H "Authorization:key=<Your Api key>" -X POST -d '{ "to": "/topics/foo-bar","data": { "message": "This is a Firebase Cloud Messaging Topic Message!"}}' https://fcm.googleapis.com/fcm/send
Kirim pesan ke grup perangkat
Mengirim pesan ke grup perangkat sangat mirip dengan mengirim pesan ke perangkat individual. Setel parameter to ke kunci notifikasi unik untuk grup perangkat
curl -H "Content-type: application/json" -H "Authorization:key=<Your Api key>" -X POST -d '{"to": "<aUniqueKey>","data": {"hello": "This is a Firebase Cloud Messaging Device Group Message!"}}' https://fcm.googleapis.com/fcm/send
Contoh menggunakan API Layanan
URL API: https://fcm.googleapis.com/fcm/send
Tajuk
Content-type: application/json
Authorization:key=<Your Api key>
Metode Permintaan: POST
Minta Badan
Pesan ke perangkat tertentu
{
"data": {
"score": "5x1",
"time": "15:10"
},
"to": "<registration token>"
}
Pesan ke topik
{
"to": "/topics/foo-bar",
"data": {
"message": "This is a Firebase Cloud Messaging Topic Message!"
}
}
Pesan ke grup perangkat
{
"to": "<aUniqueKey>",
"data": {
"hello": "This is a Firebase Cloud Messaging Device Group Message!"
}
}