【发布时间】:2017-01-14 02:48:33
【问题描述】:
我是 Firebase 的新手,我从旧的 MySql DB 适应它的主要原因是能够发送推送通知和动态链接。在过去的两天里,我一直在尝试向一组订阅了我的 node.js 脚本中的主题的人发送通知。该脚本始终返回InternalServerError。我可以从Firebase 控制台发送通知,但这对我的应用来说还不够好,因为我需要实现动态通知(即由一个用户操作触发)。
到目前为止,我不明白官方文档中的内容并尝试按照我找到的教程进行操作,我目前在这里
app.get('/push',function(req,res){
/*var title = req.params.title;
var body = req.params.body;*/
// var confName = req.params.name;
var message = { //this may vary according to the message type (single recipient, multicast, topic, et cetera)
to: '/topics/ilisten',
// collapse_key: 'your_collapse_key',
notification: {
title: 'This is Title',
body: 'This is body'
},
data: { //you can send only notification or only data(or include both)
my_key: 'Conf Name here'
}
};
fcm.send(message, function(err, response){
if (err) {
console.log("Something has gone wrong!"+err);
} else {
console.log("Successfully sent with response: ", response);
}
});
})
我的第一个问题是我应该在to 字段中做什么,以便我应用中的所有用户都能收到通知。
我还想看看这个概念在 android 代码中的正确和完整实现。如果有人有这样的代码,请在这里分享,因为它将帮助像我这样无法理解官方文档的未来Firebase用户。
【问题讨论】: