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

时间:2018-08-27 17:38:28

标签: node.js firebase google-cloud-functions

我正在关注this tutorial,到目前为止,我有适用于网络浏览器的通知(已在chrome中测试)

但是我不知道如何通过有效负载发送图标,到目前为止,我已经完成了如下发送请求正文的操作(我正在使用Firebase Cloud函数):

{
    'message': {
     token,
     'notification': {
         title,
         body,
         icon // <-- added the icon              
         }
    }
}

如果我尝试在邮件有效负载中添加图标,则在将帖子发布到google FCM URL时会收到错误的请求。

它的工作原理是不将icon属性添加到有效负载中,显然,这是错误所在,再次的问题是如何发送有效负载中的图标才能正常工作。

谢谢

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

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;
}

1 个答案:

答案 0 :(得分:1)

尝试:

{
  "message": {
    "token" : token,
    "notification": {
      "title": title,
      "body": body
    },
    "webpush": {
      "headers": {
        "Urgency": "high"
      },
      "notification": {
        "body": body,
        "requireInteraction": "true",
        "icon": icon
      }
    }
  }
}