gpt4 book ai didi

json - 收到无效的 JSON 有效负载。未知名称 click_action

转载 作者:行者123 更新时间:2023-12-04 14:51:10 28 4
gpt4 key购买 nike

所以我目前正在开发 PWA。

我现在正在使用 推送通知 而且我已经能够使用以下非常简单的 JSON 结构接收后台和前台通知。

{
"message":{
"token":"aValidToken",
"notification": {
"title": "New Content!",
"body": "A new video has been uploaded."
}
}
}

我还能够添加一个包含其他信息的数据成员,并且仍然可以毫无不便地收到通知。

现在的问题是,如果 我想添加另一个成员到 JSON,例如 点击操作 ,我发布以下内容:
{
"message":{
"token":"aValidToken",
"notification": {
"title": "New Content!",
"body": "A new video has been uploaded.",
"click_action":"https://www.google.com.ar/"
}
}
}

我收到以下错误:
{
"error": {
"code": 400,
"message": "Invalid JSON payload received. Unknown name \"click_action\" at 'message.notification': Cannot find field.",
"status": "INVALID_ARGUMENT",
"details": [
{
"@type": "type.googleapis.com/google.rpc.BadRequest",
"fieldViolations": [
{
"field": "message.notification",
"description": "Invalid JSON payload received. Unknown name \"click_action\" at 'message.notification': Cannot find field."
}
]
}
]
}
}

几乎所有其他成员都发生这种情况,例如: 优先级、图标、声音、徽章等

最后,我尝试硬编码 图标 点击操作 在 setBackgroundMessageHandler (确实被调用)中无济于事。没有图标出现,单击通知时没有任何 react 。
messaging.setBackgroundMessageHandler( (notif) => {

const notificationTitle = notif.notification.title;
const notificationOptions = {
body : notif.notification.body,
icon : '/assets/icon/icon72x72.png',
click_action : 'https://www.google.com.ar/'
};

return self.registration.showNotification(notificationTitle, notificationOptions);
});

这纯粹是一个 ionic PWA 项目,旨在在移动浏览器和桌面上运行。我会很感激你能给我的每一个小费!谢谢!

最佳答案

看起来您正在使用新的 API:https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages

但尝试使用旧 API 中的字段:
https://firebase.google.com/docs/cloud-messaging/http-server-ref

您可以使用您正在使用的 API 定义一个图标,但您的有效负载必须是:

{
"message": {
"token": "aValidToken",
"webpush": {
"notification": {
"title": "New Content!",
"body": "A new video has been uploaded.",
"icon": "your_icon"
}
}
}
}

您可以找到有关 webpush 通知字段的更多信息 here .

仅供引用,您提到的大多数其他字段(优先级、声音、徽章)是 不是 使用任一 API 在 Web 上均受支持。

编辑(2018 年 5 月 10 日):全部 notification properties新的 API 现在支持(优先级、图标、声音、徽章等)。见 this guide详情。

关于json - 收到无效的 JSON 有效负载。未知名称 click_action,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48919616/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com