云功能错误Firebase

问题描述 投票:-1回答:1

我正在尝试通过Firebase中的功能进行推送通知。

这是我在Node.JS中的代码

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

exports.sendPushNotification = functions.database.ref('Received     Downs/{owner}/{propID}')
 .onCreate(event => {
// get the owner name and propID
var owner = event.params.owner;
var propID = event.params.propID;

// Log it
console.log('Owner: ' + owner + ' Property ID: ' + propID);

// Get the list of device notification tokens.
return admin.database().ref(`/users/${owner}`).once('value', snapshot => {

  var ownerID = snapshot.val();

// This will find requester ID
return admin.database().ref(`/Received Downs/${owner}/${propID}`).once('value', snapshot => {

  // First will find the property the requester downed
  var property = snapshot.val();

  // Find the requester's name
  return admin.database().ref('/Users Info/' + property.downedBy).once('value', snapshot => {

    // Requester's ID
    var downedBy = snapshot.val();

    // Notification details.
    const payload = {
      notification: {
        title: 'You have a new request!',
        body: `${downedBy.name} is now following you.`,
        sound: 'default'
      }
    };

    // Listing all tokens. (the function save the keys of given variable)
    // const tokens = Object.keys(getDeviceTokens.val());
   // var fcmToken = "dzJLM-JdIt8:APA91bHBJJP6t3Z0_T7kEFDrLLsu5T_NpYsR6QmJz2EJhpK88SV1ZfemoyCtC_6hl3_0sCPdzkvlQFoAFhlWn4xTQOY3k5P8JMvdYFyeNBN1lHceQtytE0y-9oTP6qgKspi9p9E8V9dB";

    // Send to all tokens of a device
    admin.messaging().sendToDevice(ownerID.token, payload)
      .then(response => {
        console.log("Successfully sent message:", response);
      }).catch(function(error) {
        console.log("Error sending message:", error);
      });

  })

 })

})
})

这是我在Firebase Functions的LOGS中获得的内容

enter image description here

当我使用具有fem令牌的变量时,键入,它可以正常工作,但不是从我从Firebase实时数据库中获取时。谁能告诉我为什么?

node.js firebase firebase-cloud-messaging google-cloud-functions
1个回答
0
投票

我有错误路径的问题返回admin.database()。ref(/users/${owner}

© www.soinside.com 2019 - 2024. All rights reserved.