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

后端 未结 16 1305
南旧
南旧 2020-11-22 10:17

I\'m starting with the new Google service for the notifications, Firebase Cloud Messaging.

Thanks to this code https://github.com/firebase/quickstart-a

16条回答
  •  长发绾君心
    2020-11-22 11:02

    Examples using curl

    Send messages to specific devices

    To send messages to specific devices, set the to the registration token for the specific app instance

    curl -H "Content-type: application/json" -H "Authorization:key="  -X POST -d '{ "data": { "score": "5x1","time": "15:10"},"to" : ""}' https://fcm.googleapis.com/fcm/send
    

    Send messages to topics

    here the topic is : /topics/foo-bar

    curl -H "Content-type: application/json" -H "Authorization:key="  -X POST -d '{ "to": "/topics/foo-bar","data": { "message": "This is a Firebase Cloud Messaging Topic Message!"}}' https://fcm.googleapis.com/fcm/send
    

    Send messages to device groups

    Sending messages to a device group is very similar to sending messages to an individual device. Set the to parameter to the unique notification key for the device group

    curl -H "Content-type: application/json" -H "Authorization:key="  -X POST -d '{"to": "","data": {"hello": "This is a Firebase Cloud Messaging Device Group Message!"}}' https://fcm.googleapis.com/fcm/send
    

    Examples using Service API

    API URL : https://fcm.googleapis.com/fcm/send

    Headers

    Content-type: application/json
    Authorization:key=
    

    Request Method : POST

    Request Body

    Messages to specific devices

    {
      "data": {
        "score": "5x1",
        "time": "15:10"
      },
      "to": ""
    }
    

    Messages to topics

    {
      "to": "/topics/foo-bar",
      "data": {
        "message": "This is a Firebase Cloud Messaging Topic Message!"
      }
    }
    

    Messages to device groups

    {
      "to": "",
      "data": {
        "hello": "This is a Firebase Cloud Messaging Device Group Message!"
      }
    }
    

提交回复
热议问题