如何使用 fcm(firebase cloud messaging) 和 scala play 框架来发送通知?

How to use fcm(firebase cloud messaging) with scala play framework to send notification?

我正在尝试使用 fcm(firebase 云消息传递)创建网络推送通知,所以我首先在 firebase 上创建我的项目,然后我获得了添加到 HTTP [=] 的 API 密钥17=] 请求,我使用 play 提供的 wsClient 向 firebase 端点发送 POST HTTP 请求,但我收到错误 401,我尝试使用服务器密钥、旧密钥,但结果始终相同。

def sendNotification()={
var  url = "https://fcm.googleapis.com/fcm/send"
val request: WSRequest = ws.url(url)
  .withHttpHeaders("Authorization"->s" $myserverKey","Content-Type" ->"application/json")
val data = Json.obj()
val futureResponse = request.post(data)
Await.result(futureResponse, Duration.Inf)
Logger.warn(s"send notification to firebase $futureResponse")

错误信息:

401: The request was missing an Authentication Key (FCM Token). Please, 
refer to section "Authentication" of the FCM documentation, at 
https://firebase.google.com/docs/cloud-messaging/server.

您似乎没有遵循将服务器密钥放入授权中的协议 header。根据 documentation,它应该是这样的:

Authorization: key=YOUR-KEY