Firebase FCM http v1 图标未在浏览器中显示

jac*_*per 0 node.js firebase google-cloud-functions

我正在关注本教程,到目前为止我有适用于网络浏览器的通知(在 Chrome 中测试)

但我不知道如何通过有效负载发送图标,到目前为止我所做的是发送请求正文,如下所示(我正在使用 firebase 云函数):

{
    'message': {
     token,
     'notification': {
         title,
         body,
         icon // <-- added the icon              
         }
    }
}
Run Code Online (Sandbox Code Playgroud)

如果我尝试在消息负载中添加图标,当我向 google FCM URL 发送帖子时,我会收到错误的请求。

它可以在不将图标属性添加到有效负载的情况下工作,显然,这就是错误,问题又是如何将有效负载中的图标发送到工作。

谢谢

编辑,我正在发布我的帖子功能:

async function notification(messageBody) {
    const api = 'https://fcm.googleapis.com/v1/projects/{projectID}/messages:send';
    const accessToken = await getAccessToken();
    const response = await fetch(api, {
        headers: {
            'Accept': 'application/json',
            'Content-type': 'application/json',
            'Authorization': `Bearer ${accessToken}`
        },
        method: 'POST',
        body: messageBody
    });
    return response;
}
Run Code Online (Sandbox Code Playgroud)

Jam*_*oag 7

尝试:

{
  "message": {
    "token" : token,
    "notification": {
      "title": title,
      "body": body
    },
    "webpush": {
      "headers": {
        "Urgency": "high"
      },
      "notification": {
        "body": body,
        "requireInteraction": "true",
        "icon": icon
      }
    }
  }
}
Run Code Online (Sandbox Code Playgroud)