通过POST发送推送通知需要哪个令牌

时间:2018-02-24 17:14:00

标签: firebase http-post firebase-cloud-messaging

我正在尝试设置可以使用Firebase发送推送通知的REST API服务器。 Google documentation表示这是一个有效的POST请求,作为开头:

POST https://fcm.googleapis.com/v1/projects/myproject-b5ae1/messages:send HTTP/1.1

Content-Type: application/json
Authorization: Bearer ya29.ElqKBGN2Ri_Uz...HnS_uNreA
{
  "message":{
    "topic" : "foo-bar",
    "notification" : {
      "body" : "This is a Firebase Cloud Messaging Topic Message!",
      "title" : "FCM Message",
      }
   }
}

但是,我无法弄清楚这里有哪个授权承载。在firebase控制台上有很多它们,我已经尝试了每一个,没有工作。它们都导致了401响应。

我在哪里可以找到此请求的预期持有者?

谢谢!

1 个答案:

答案 0 :(得分:2)

我发现使用legacy protocols发送推送通知更容易。我们只需要可以在Firebase控制台中找到的服务器密钥。

Firebase控制台>项目设置>云消息传递>服务器密钥

HTTP请求如下所示:

curl -X POST -H "Authorization: key=<your_server_key>" -H "Content-Type: application/json" -d '{
  "notification": {
    "body" : "This is a Firebase Cloud Messaging Topic Message!",
    "title" : "FCM Message",
  },
  "to": "/topics/<topic_name>"
}' "https://fcm.googleapis.com/fcm/send"

检查Server Reference是否有其他API用于服务器实施。