这是我第一次使用Cloud Functions for Firebase和Node.js,所以
我不知道为什么我在Firebase控制台上看不到任何日志。
至少,我已成功部署了以下功能
'use strict';
const functions = require('firebase-functions');
//import admin module
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
/* Listens for new messages added to events and sends a notification to
subscribed users */
exports.pushNotification =
functions.database.ref('/events/{pushId}').onWrite( event => {
console.log('Push notification event triggered');
/* Grab the current value of what was written to the Realtime Database
*/
var valueObject = event.data.val();
/* Create a notification and data payload. They contain the
notification information, and message to be sent respectively */
const payload = {
data: {
eventType: valueObject.eventType,
receiver: valueObject.receiver,
requester: valueObject.requester
}
};
/* Create an options object that contains the time to live for the
notification and the priority. */
const options = {
priority: "high",
timeToLive: 60 * 60 * 24 //24 hours
};
return admin.messaging().sendToTopic(valueObject.receiver, payload,
options).then(function (response) {
console.log("Successfully sent message:", response);
})
.catch(function (error) {
console.log("Error sending message:", error);
});
});
但是,即使我将一些数据写入“事件”数据库,我也无法在Firebase控制台上看到任何日志消息。 这是不是意味着这个功能根本没有触发?
如果有人能说出这个问题的原因,我真的很感激。
答案 0 :(得分:0)
如果您在控制台中正确设置了应用程序,那么如果该函数被触发,则没有理由不进行日志记录。
这使您可能无法启动该功能。可能的原因是数据没有写入函数中提供的路径。
那么,您是要向/events
添加一个值,例如'true'
还是'ABC'
,还是要添加一个孩子,例如{'ABC' = true}
?
在.ref(/events/{pushId})
的情况下,将在后一种情况下调用该函数,而不是前者。