Home > Backend Development > PHP Tutorial > How to Send Firebase Cloud Messaging Notifications Using the REST API?

How to Send Firebase Cloud Messaging Notifications Using the REST API?

Barbara Streisand
Release: 2024-12-17 19:58:11
Original
550 people have browsed it

How to Send Firebase Cloud Messaging Notifications Using the REST API?

Sending Firebase Cloud Messaging Notifications via REST API

Firebase Cloud Messaging (FCM) provides server-side APIs for sending notifications without using the Firebase Console. To accomplish this, you can utilize the REST API using cURL.

Steps:

  1. Obtain Authorization Token:
    Before making API calls, you need an authorization token. Visit https://firebase.google.com/docs/cloud-messaging/server#authorizing_send_requests to understand the authorization process.
  2. Send Message:
    Use cURL to call the FCM HTTP endpoint, specifying the authorization token in the header:
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"
        }
    }"
Copy after login

Replace with your actual API key and with the device token you wish to send the notification to.

Other Options:

In addition to the REST API, FCM offers Admin SDKs for various platforms. These specifically built-for-purpose SDKs provide an easier interface for sending notifications from within the respective environments. Here's a list of supported platforms: https://firebase.google.com/docs/cloud-messaging/server#client_sdk_api

Historical Note:

An older method using a decommissioned API has been removed from this response. Always refer to the latest documentation provided by Firebase for the most up-to-date information.

The above is the detailed content of How to Send Firebase Cloud Messaging Notifications Using the REST API?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template