通过 Firebase 的 FCM API 测试发送通知

Sending a notification through Firebase's FCM API Test

我目前正在尝试使用 Firebase 的“试试这个 API”界面发送通知。 我用这个填充了我的请求正文:

{
  "validateOnly": false,
  "message": {
    "notification": {
      "body": "Body",
      "title": "Title"
    }
  }
}

以及具有

的RequestParameters
projects/myprojectid

我没有检查 Google API 密钥,因为我的项目没有密钥,但我检查了 Google OAuth 2.0。

执行后,我得到这个错误:

{
  "error": {
    "code": 400,
    "message": "Recipient of the message is not set.",
    "status": "INVALID_ARGUMENT",
    "details": [
      {
        "@type": "type.googleapis.com/google.rpc.BadRequest",
        "fieldViolations": [
          {
            "field": "message",
            "description": "Recipient of the message is not set."
          }
        ]
      },
      {
        "@type": "type.googleapis.com/google.firebase.fcm.v1.FcmError",
        "errorCode": "INVALID_ARGUMENT"
      }
    ]
  }
}

经过一番研究,我不明白请求中缺少什么。请求的所有参数都是强制性的吗?

您没有指定该消息是给谁的,而这正是错误消息试图告诉您的内容。您可以通过在 JSON.

中包含一个带有多个设备令牌之一的 token 密钥,或 topiccondition 密钥来实现

另请参阅 building requests to send a message 上的 Firebase 文档,了解更多信息和每个示例。