【问题标题】:Firebase FCM http v1 icon not showing in browserFirebase FCM http v1 图标未显示在浏览器中
【发布时间】:2018-08-27 17:38:28
【问题描述】:

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

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

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

如果我尝试在消息负载中添加图标,我在向 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;
}

【问题讨论】:

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


    【解决方案1】:

    试试:

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

    【讨论】:

    • 我收到此错误,但感谢您的回答:{ 错误:{ 代码:400,消息:'收到无效的 JSON 有效负载。未知名称“webpush”:找不到字段。\n收到的 JSON 负载无效。未知名称“通知”:找不到字段。',状态:'INVALID_ARGUMENT',详细信息:[ [Object] ] } }
    • 谢谢,我想我正在向外部消息发送有效负载,这个答案也帮助了我:stackoverflow.com/questions/48919616/…
    猜你喜欢
    • 1970-01-01
    • 2014-07-18
    • 2016-10-03
    • 1970-01-01
    • 2016-04-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多