【发布时间】:2018-11-01 03:50:13
【问题描述】:
我试图在有人单击“开始”按钮时通知我的用户,但我的 firebase 函数日志中不断出现一些错误。
未捕获的异常&
提供给 sendToDevice() 的注册令牌必须是非空字符串或非空数组
exports.observeGoing = functions.database.ref('/going/{postId}/{uid}').onCreate((snapshot,context) => {
var postId = context.params.postId;
var uid = context.params.uid;
console.log('User: ' + uid + ' is going to your activity');
return admin.database().ref('/users/' + uid).once('value', snapshot => {
var creatorOfPost = snapshot.val();
admin.database().ref('/users/' + uid).once('value', snapshot => {
var userGoing = snapshot.val();
var payload = {
notification: {
body: userGoing.usernames + " is going",
sound: "default"
}
}
admin.messaging().sendToDevice(creatorOfPost.fcmToken, payload)
.then((response) => {
console.log('Successfully send message:', response);
return response
})
.catch((error) =>{
console.log('Error sending message:', error);
});
})
})
})
【问题讨论】:
-
能否提供堆栈跟踪或那些错误?
-
我不确定你的意思
-
你能分享完整的错误信息吗?没有这个就很难判断出了什么问题
-
记录
creatorOfPost.fcmToken的值
标签: javascript firebase firebase-realtime-database firebase-cloud-messaging google-cloud-functions