【问题标题】:Error upon Cloud Function for Firebase deploymentCloud Function for Firebase 部署时出错
【发布时间】:2020-04-29 03:28:14
【问题描述】:

我一直在尝试将 Cloud Function 部署到我的 Firebase 项目。 这是我第一次这样做,也是我第一次使用 JavaScript 编程。

这是我在 Node.JS 中的代码:

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

const firebaseTriggers = functions.region('europe-west1').firestore;
const db = admin.firestore();

exports.postNotification = firebaseTriggers
      .document('/post notifications/{notificatioId}').onWrite((snap, context) => {
      const notifcationRecieverId = snap.data().mReciever;
      const payload = {
        data: {
            notification_type: 'POST',
            title: snap.data().mTitle,
            body: snap.data().mDescription,
            sender_id: snap.data().mSender,
            reciever_id: snap.data().mReciever,
            notification_id: context.params.notificatioId
        }
      };
      return db.collection('dog owners')
        .document(notifcationRecieverId)
        .get()
        .then(recieverDoc => {
            console.log('Retrieving FCM tokens');
            const tokens = recieverDoc.data().mTokens;
            console.log('Sending notification payload');
            return admin.message().sendToDevice(tokens, payload);
        });
});

在部署时,我收到以下错误:

谁能帮我理解为什么?

【问题讨论】:

  • 在 Stack Overflow 上请不要使用文字图片。最好将文本复制到问题中,以便于阅读和搜索。我们不必单击即可查看所有相关信息。

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


【解决方案1】:

首先,您的收藏名称中有空格。这是不好的对流。

post notifications => postNotifications

【讨论】:

    猜你喜欢
    • 2023-03-13
    • 2018-11-27
    • 2021-05-14
    • 2019-09-11
    • 2020-03-01
    • 2021-10-17
    • 2022-08-19
    • 1970-01-01
    • 2020-11-13
    相关资源
    最近更新 更多