【发布时间】:2017-11-08 23:30:48
【问题描述】:
对于使用 Firebase 作为数据库的 AppInventor 应用,我想为应用用户提供唯一的用户 ID。在寻找了一些选项后,我想到我可以使用应用程序请求的 Cloud HTTP 函数,返回的数据将是通过简单地递增 UserIds 表中的最后一个 UserId 生成的 UserId(也不确定是不是一个)。
故事就是这样,但我无法制作以下代码来部署(如果可以,它不会像我预期的那样工作)。它正确读取了最后一个UserId,但我只能让它覆盖之前的数据。
它会在functions.https 中的"." 中引发意外令牌错误。
const functions = require('firebase-functions');
// Import and initialize the Firebase Admin SDK.
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
var LastUserId = function f() {return admin.database().ref('UserIds').limitToLast(1)}
exports.addWelcomeMessages = functions.https.onRequest((request, response)) => {
var ref = admin.database().ref('UserIds');
// this new, empty ref only exists locally
var newChildRef = ref.push();
// we can get its id using key()
console.log('my new shiny id is '+newChildRef.key());
// now it is appended at the end of data at the server
newChildRef.set({User : LastUserId + 1});
});
【问题讨论】:
标签: javascript firebase firebase-realtime-database google-cloud-functions app-inventor