gpt4 book ai didi

node.js - 带有前缀的 Node JS 谷歌云消息传递主题出现错误 : Malformed topic name

转载 作者:太空宇宙 更新时间:2023-11-03 22:22:27 26 4
gpt4 key购买 nike

我想使用 Nodejs 创建后端服务来向所有订阅者发送通知。我想让它动态化,我已经阅读了如何使用 NodeJS 使用 GCM 的文档 this link ,它表示“主题名称可以选择以“/topics/”为前缀

没有前缀,一切正常,但是当我尝试在其上添加前缀时,出现“错误:主题名称格式错误”

这是我现在的代码

app.post('/notify', (request, response) => {
// console.log(request.body);
var message = {
android: {
ttl: 3600 * 1000, // 1 hour in milliseconds
priority: 'normal',
notification: {
title: request.body.fullname + ' want to join',
body: 'email: ' + request.body.email + '; tel: ' + request.body.no_telp,
icon: 'stock_ticker_update',
color: '#0088aa'
},
data: request.body
},
topic: '/register/guest'
};

admin.messaging().send(message)
.then((res) => {
// Response is a message ID string.
console.log('Successfully sent message:', res);
response.send("success");
})
.catch((error) => {
console.log('Error sending message:', error);
response.send('error');
});

})

最佳答案

在我看来,第 https://firebase.google.com/docs/cloud-messaging/admin/send-messages 页示例代码第一行中的注释是不正确的。在“定义消息”下明确指出

The topic name must not include the /topics/ prefix.

关于node.js - 带有前缀的 Node JS 谷歌云消息传递主题出现错误 : Malformed topic name,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52668452/

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