【问题标题】:Which token is needed to send push notifications through POST通过 POST 发送推送通知需要哪个令牌
【发布时间】:2018-02-24 17:14:00
【问题描述】:

我正在尝试设置一个可以使用 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 响应。

我在哪里可以找到此请求的预期承载?

谢谢!

【问题讨论】:

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


【解决方案1】:

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

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。

【讨论】:

  • 谢谢,我会考虑的。但由于 Bob Snyder 的链接效果很好,我想我会去的
猜你喜欢
  • 2014-08-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-04-24
  • 1970-01-01
  • 1970-01-01
  • 2020-09-20
相关资源
最近更新 更多