David Corral David Corral - 6 months ago 4016
PHP Question

How can I send a Firebase Cloud Messaging notification without use the Firebase Console?

I'm starting with the new Google service for the notifications,

Firebase Cloud Messaging
. Thanks to this code https://github.com/firebase/quickstart-android/tree/master/messaging I was be able to send notifications from my Firebase User Console to my Android device. The thing is:

Is there any API or way to send a notification without use the Firebase console? I mean, for example, a PHP API or something like that, to create notifications from my own server directly.

Thanks!

Answer

Firebase Cloud Messaging has server-side APIs that you can call to send messages. See https://firebase.google.com/docs/cloud-messaging/server.

Sending a message can be as simple as using curl to call a HTTP end-point. See https://firebase.google.com/docs/cloud-messaging/server#implementing-http-connection-server-protocol

curl -X POST --header "Authorization: key=<your key>" --Header "Content-Type: application/json" https://fcm.googleapis.com/fcm/send -d "{\"to\":\"<your device id>\",\"data\":{\"message\":\"Yellow\"}}"
Comments