Home >Backend Development >PHP Tutorial >Can I Send Firebase Cloud Messaging Notifications Without Using the Firebase Console?

Can I Send Firebase Cloud Messaging Notifications Without Using the Firebase Console?

Patricia Arquette
Patricia ArquetteOriginal
2024-12-25 08:45:09233browse

Can I Send Firebase Cloud Messaging Notifications Without Using the Firebase Console?

Send Firebase Cloud Message notifications without Firebase console

Question:

Me You've started using Firebase Cloud Messaging, the latest notification service from Google. Thanks to this code https://github.com/firebase/quickstart-android/tree/master/messaging I am able to send notifications to my Android device from Firebase User Console.

Is there an API or method to send notifications without using the Firebase console? I mean, like a PHP API or something like that for creating notifications directly from my server.

Answer:

From now on, for an example of sending messages from the v1 API using CURL, see Sending a message to a specific device.

curl -X POST -H "Authorization: Bearer ya29.ElqKBGN2Ri_Uz...HnS_uNreA" -H "Content-Type: application/json" -d '{
"message":{
   "notification":{
     "title":"FCM Message",
     "body":"This is an FCM Message"
   },
   "token":"bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1..."
}}' https://fcm.googleapis.com/v1/projects/myproject-b5ae1/messages:send

You need to obtain an authorization token to make this call. This process is documented in the authorization send request.

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

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

curl -X POST --header "Authorization: key=<API_ACCESS_KEY>" \
    --Header "Content-Type: application/json" \
    https://fcm.googleapis.com/fcm/send \
    -d "{"to":"<YOUR_DEVICE_ID_TOKEN>","notification":{"title":"Hello","body":"Yellow"}}}"

You can call this REST API in any environment, but there are specialized so-called management SDKs for many platforms listed here.

The above is the detailed content of Can I Send Firebase Cloud Messaging Notifications Without Using the Firebase Console?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn