【发布时间】:2019-11-26 01:04:46
【问题描述】:
我想在从实时数据库中成功查询设备令牌后发送通知
我的消息
let push_token = [];
let message = {
message: {
token: push_token,
notification: {
title: 'new post',
body: title,
},
data: {
post_id: id,
},
},
};
查询令牌代码然后发送通知
admin
.database()
.ref('/devices_token')
.once('value', snapshot => {
snapshot.forEach(function(data) {
let val = data.val();
push_token.push(val.fcmToken);
});
})
.then(() => {
admin.messaging
.send(message)
.then(response => {
// Response is a message ID string.
console.log('Successfully sent message:', response);
})
.catch(error => {
console.log('Error sending message:', error);
});
});
});
控制台出错
TypeError: admin.messaging.send is not a function at admin.database.ref.once.then
【问题讨论】:
-
admin.messaging().send(message)
标签: javascript firebase-realtime-database firebase-cloud-messaging google-cloud-functions