Firebase FCM - 为啥会收到:有效负载错误,无效的“android”(或“apns”)属性
Posted
技术标签:
【中文标题】Firebase FCM - 为啥会收到:有效负载错误,无效的“android”(或“apns”)属性【英文标题】:Firebase FCM - Why am I getting: payload error, invalid 'android' (or 'apns') propertyFirebase FCM - 为什么会收到:有效负载错误,无效的“android”(或“apns”)属性 【发布时间】:2019-03-26 09:30:14 【问题描述】:我正在使用云功能 (node.js) 向设备发送通知。我的有效载荷设置如下:
const payload =
notification:
title: payloadSender,
body: payloadMessage,
,
data:
chatId: chatId,
,
android:
priority: 'normal',
collapse_key: chatId,
//todo how to set badge?
notification:
sound: 'messageSent.wav',
,
,
apns:
headers:
'apns-priority': '5',
'apns-collapse-id': chatId,
,
payload:
aps:
badge: newUnreads,
sound: 'messageSent.wav',
'content-available': 1,
;
根据 Firebase 文档,您可以将“android”和“apns”字段用于设备特定行为。以下是 FCM 发送的消息的 JSON 表示 found here:
"name": string,
"data":
string: string,
...
,
"notification":
object(Notification)
,
"android":
object(AndroidConfig)
,
"webpush":
object(WebpushConfig)
,
"apns":
object(ApnsConfig)
,
// Union field target can be only one of the following:
"token": string,
"topic": string,
"condition": string
// End of list of possible types for union field target.
为什么我收到错误 Messaging payload contains an invalid "android" property. Valid properties are "data" and "notification".
和 Messaging payload contains an invalid "apns" property. Valid properties are "data" and "notification".
?
【问题讨论】:
您找到解决方案了吗?我也有同样的困难。 【参考方案1】:根据您的帖子,我无法判断您使用的是哪个版本,但请注意,平台覆盖功能仅适用于 v1,不旧版。
另外,我不确定您是否刚刚从示例负载中删除了一些项目,但其中有很多不必要的逗号 (,
) 会破坏 JSON。尝试使用在线 JSON 格式化程序来仔细检查您的有效负载。我在你的上面试了一个,在消除所有错误后得到了这个结果:
"notification":
"title": "payloadSender",
"body": "payloadMessage"
,
"data":
"chatId": "chatId"
,
"android":
"priority": "normal",
"collapse_key": "chatId",
//todo how to set badge? IIRC, Badges can be enabled via method inside the Android Notification builder
"notification":
"sound": "messageSent.wav"
,
"apns":
"headers":
"apns-priority": "5",
"apns-collapse-id": "chatId"
,
"payload":
"aps":
"badge": "newUnreads",
"sound": "messageSent.wav",
"content-available": 1 // Double check this one if you are to actually use content-available or content_available for FCM
只需根据需要再次切换变量即可。
【讨论】:
刚刚使用了关于 JSON 的副本..Messaging payload contains an invalid "android" property. Valid properties are "data" and "notification
@Rajamohan 平台覆盖仅适用于 v1。我认为您正在使用旧版。
@AL。您能否分享一下我如何使用 V1?以上是关于Firebase FCM - 为啥会收到:有效负载错误,无效的“android”(或“apns”)属性的主要内容,如果未能解决你的问题,请参考以下文章
向 FCM API 发送请求时收到无效的 JSON 有效负载
Firebase FCM通知click_action有效内容