我试图向具有Firebase函数的FireBase数据库发送带有数据更新的通知。在函数执行之后,我将面临这些错误。
下面也是我的函数数据库快照。请仔细检查,看看是否有任何错误。
还有我的js密码。
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.sendNotification = functions.database.ref('/Lecture_Materials/{MIS}/{MISId}')
.onWrite(event => {
// Grab the current value of what was written to the Realtime Database.
var eventSnapshot = event.data;
var str1 = "Lecture note uploaded is: ";
var str = str1.concat(eventSnapshot.child("name").val());
console.log(str);
var topic = "Management.Information.System";
var payload = {
data: {
name: eventSnapshot.child("name").val(),
}
};
// Send a message to devices subscribed to the provided topic.
return admin.messaging().sendToTopic(topic, payload)
.then(function (response) {
// See the MessagingTopicResponse reference documentation for the
// contents of response.
console.log("Successfully sent message:", response);
return;
})
.catch(function (error) {
console.log("Error sending message:", error);
});
});
发布于 2018-06-25 14:13:09
1.0版本的SDK更改了数据库onW区事件的API。
https://stackoverflow.com/questions/-100005508
复制相似问题