admin管理员组文章数量:1410697
I am trying to send the notification to devices within a circle of a radius of a point using firebase cloud functions. I am able to get the id of the devices within the circle but I am not able to get the token, the token is null as printed using console.log(token).
const getdevicetokenpromise = db.ref('/DriversAvailable/{key}/token').once('value');
console.log(key); //this value is right
return getdevicetokenpromise.then(result => {
console.log(result.val()); //this value is null, this is the problem
var token = result.val();
const payload = {
notification: {
title: 'title',
body: 'hey, well done dude',
icon: 'default'
}
};
return admin.messaging().sendToDevice(token, payload)
.then((response)=> {
return console.log("Successfully sent message:", response);
})
.catch((error) =>{
console.log("Error sending message:", error);
});
});
I have tried most of the things suggested on stackoverflow but coudln't find the solution. Thanks.
I am trying to send the notification to devices within a circle of a radius of a point using firebase cloud functions. I am able to get the id of the devices within the circle but I am not able to get the token, the token is null as printed using console.log(token).
const getdevicetokenpromise = db.ref('/DriversAvailable/{key}/token').once('value');
console.log(key); //this value is right
return getdevicetokenpromise.then(result => {
console.log(result.val()); //this value is null, this is the problem
var token = result.val();
const payload = {
notification: {
title: 'title',
body: 'hey, well done dude',
icon: 'default'
}
};
return admin.messaging().sendToDevice(token, payload)
.then((response)=> {
return console.log("Successfully sent message:", response);
})
.catch((error) =>{
console.log("Error sending message:", error);
});
});
I have tried most of the things suggested on stackoverflow but coudln't find the solution. Thanks.
Share Improve this question edited Jun 28, 2018 at 19:51 Doug Stevenson 319k36 gold badges456 silver badges473 bronze badges asked Jun 28, 2018 at 19:42 GURJEET SINGHGURJEET SINGH 131 silver badge5 bronze badges1 Answer
Reset to default 5It looks like you're assuming that the value of key
should be inserted into this string:
const getdevicetokenpromise = db.ref('/DriversAvailable/{key}/token').once('value');
That's not the way it's working, though. You are literally querying for that exact string, without key
being inserted. I imagine you meant to use JavaScript syntax for variable interpolation using backticks around the string and ${} to delimit the variable:
const getdevicetokenpromise = db.ref(`/DriversAvailable/${key}/token`).once('value');
本文标签:
版权声明:本文标题:javascript - Error: Registration token(s) provided to sendToDevice() must be a non-empty string or a non-empty array - Stack Ove 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745035701a2638771.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论