简体   繁体   English

如何从Rest API发送推送通知

[英]How to send push notification from Rest API

I have created my App in Firebase and configured for cloud messaging. 我已经在Firebase创建了我的应用程序,并配置了云消息传递功能。 When I am sending the notification from Firebase Console, device gets the notification but if I try to send via Rest API (Using PostMan). Firebase控制台发送通知时,设备会收到通知,但是如果我尝试通过Rest API(使用PostMan)发送。 Then notification not coming to device but the response is showing as Success. 然后通知未到达设备,但响应显示为成功。

Here is my PostMan request 这是我的邮递员要求

URI - https://fcm.googleapis.com/fcm/send URI- https://fcm.googleapis.com/fcm/send

Header: Content-Type:application/json Authorization:key=MY_SERVER_KEY 标题:Content-Type:应用程序/ json授权:key = MY_SERVER_KEY

Body: { "data": { "title": "Firebase", "detail": "I am firebase" }, "to" : "MY FCM TOKEN HERE" } 正文:{“数据”:{“标题”:“ Firebase”,“详细信息”:“我是Firebase”},“至”:“我的FCM令牌在这里”}

Response : { "multicast_id": 7834540847388366233, "success": 1, "failure": 0, "canonical_ids": 0, "results": [ { "message_id": "0:1532422122326299%ebf5f25ef9fd7ecd" } ] } 响应:{“ multicast_id”:7834540847388366233,“ success”:1,“ failure”:0,“ canonical_ids”:0,“ results”:[{“ message_id”:“ 0:1532422122326299%ebf5f25ef9fd7ecd”}]}

I have searched and it seems the way mentioned in documentation is same as I am following Can anyone let me know why it is not working? 我进行了搜索,似乎文档中提到的方式与我遵循的方式相同。有人可以让我知道为什么它不起作用吗? Thanks 谢谢

I am posting here so as to guide others. 我在这里发布,以指导他人。 As per the guidance of @rv7284, We need to send the data in notification key rather any other key. 按照@ rv7284的指导,我们需要通过notification密钥而不是其他任何密钥发送数据。

So While requesting the body should look like this, Other request parameter like header and all will be same as mentioned in the question. 因此,在请求正文时应该看起来像这样,其他请求参数(如header和all)将与问题中提到的相同。

{ "notification": {
 "title": "Firebase",
 "detail": "I am firebase"
},
 "to" : "YOUR FCM TOKEN"
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM