【发布时间】:2019-02-12 16:51:24
【问题描述】:
我正在通过在 firebase 云功能中使用 onWrite(snapshot, context) 来收听活动节点。我想根据actives的变化来获取token节点的值。
我的触发函数如下。
exports.sendNotification = functions.database.ref('root/users/{userid}/actives/{pushId}')
.onWrite((event, context) => {
var token;
var active_userid = context.params.pushId;
if(event.after._data != null){
console.log(event.after.ref.parent.parent);
}else{
console.log('data is null')
}
return 0;
});
如何获取token节点并读取其值?
【问题讨论】:
-
您可以登录
active_userid并告诉我您在控制台中得到了什么吗?在var active_userid = context.params.pushId;之后写console.log(active_userid) -
@PeterHaddad 使用关于我得到 hasnain 的图像
-
让你的 pushId 不为 null 或 ""(empty)。
-
@MayurPatel 这不是 pushId。在下面查看我的答案
标签: android firebase firebase-realtime-database google-cloud-functions