【问题标题】:Getting error while deploying node.js cloud function部署 node.js 云功能时出错
【发布时间】:2018-11-07 22:30:36
【问题描述】:

我在我的应用程序中执行 firebase 通知。 这是我的 node.js 函数

'use strict'

const functions = require('firebase-functions');
const admin=require('firebase-admin');
admin.initializeApp(functions.config().firebase);

exports.sendNotificaiton=functions.database.ref('/Notifications/{userKey}/{notification_id}').
onWrite(event => {
const userKey = event.params.userKey;
const notification = event.params.notification;

console.log('The userKey is ', userKey);

});

我的 firebase 数据库结构是

函数错误是

请帮帮我。 提前致谢

【问题讨论】:

    标签: node.js firebase firebase-cloud-messaging google-cloud-functions firebase-notifications


    【解决方案1】:

    修改你的代码

    从此

    exports.sendNotificaiton=functions.database.ref('/Notifications/{userKey}/{notification_id}').
    onWrite(event => {
    const userKey = event.params.userKey;
    const notification = event.params.notification;
    
    console.log('The userKey is ', userKey);
    
    });
    

    到此

    exports.sendNotificaiton=functions.database.ref('/Notifications/{userKey}/{notification_id}').onWrite((change, context) => {
    
    const userKey = context.params.userKey;
    const notification = context.params.notification;
    
    console.log('The userKey is ', userKey);
    
    });
    

    您正在为onWrite() 使用旧的event 触发器,现在您需要传递上下文和您的数据快照(更改)。

    当写入事件触发您的数据库时,onWrite 还具有 beforeafter

    在此处查看文档:https://firebase.google.com/docs/functions/database-events?hl=en

    有关通知,请参见 github 上的通知示例:https://github.com/firebase/functions-samples/tree/Node-8/fcm-notifications

    【讨论】:

      猜你喜欢
      • 2018-02-22
      • 1970-01-01
      • 2021-02-24
      • 2019-09-30
      • 2019-06-26
      • 2021-12-01
      • 1970-01-01
      • 2018-08-03
      相关资源
      最近更新 更多