首页 > 解决方案 > “消息”中的未知名称“time_to_live”:

问题描述

我正在尝试通过 firebase 发送推送通知:

await admin.messaging().sendAll({
token: 'some token',
data: {val1: '1', val2: '2'},
time_to_live: 300,
});

我收到下一个错误:

{"message":"发送推送通知失败,收到无效的 JSON 有效负载。'message' 处的未知名称 "time_to_live": 找不到字段。","level":"error"}

标签: node.jsfirebasefirebase-cloud-messagingfirebase-admin

解决方案


在 firebasetime_to_live的 key 中ttl,我也使用这个请求正文在 android 应用程序中发送推送通知:

const body = {
  notification: {
    title: 'xxxx',
    body: "xxxxxxxx"
  },
  data: {
    notification_message: "xxxxxx"
  },
  token: 'xxxxxx',
  android: {
    ttl: 3600,
    notification: { icon: 'xxxxx', color: '#b2b2b2' }
  }
}

await admin.messaging().send(body)

在 的情况下使用ttl密钥time_to_live


推荐阅读