我不明白为什么这不起作用,因为这是基本的。
这是我的代码:
// Init cloud functions
const functions = require('firebase-functions');
const admin = require('firebase-admin');
// Used to access entire JSON Nodes as Admin...
admin.initializeApp();
exports.verifyIAP = functions.database.ref('/Users/{userid}/IAP/{groupid}/{rdate}')
.onCreate((snapshot, context) => {
const groupId = context.params.groupid;
console.log('GroupID: ', groupId);
const receiptDate = context.params.rdate;
console.log('receipt Date: ', receiptDate);
const userId = context.params.userid;
console.log('UserID: ', userId);
const receipt = snapshot.val().ReceiptData;
console.log('receipt Data: ', receipt);
});
当函数触发时,日志将所有变量显示为未定义!?
我错过了什么!?
您的函数运行良好。我刚刚测试了它,问题可以指向如何插入数据。出于测试目的,以下是我用来插入数据并触发函数的示例代码:
// Import Admin SDK
var admin = require("firebase-admin");
var serviceAccount = require("./*******.json");
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: "https://********.firebaseio.com/"
});
var db = admin.database();
var ref = db.ref("Users");
ref.set({
"userId" : {
"IAP" : {
"groupId" : {
"rdate" : {
"ReceiptData" : "testVAl"
}
}
}
}
}).then(result => {
console.log('done')
process.exit(0)
});