一些更多的函数来实现读写

1.编写一个简单的数据来测试连接是否正常

function myFunction(){
 var firebaseUrl = "https://example-app.firebaseio.com/";
 var secret = "secret-key";
 var base = FirebaseApp.getDatabaseByUrl(firebaseUrl, secret);
 base.setData("test", "Hello Firebase"); 
}

2.阅读所有数据

function getAllData() {
         var firebaseUrl = "https://example-app.firebaseio.com/";
         var secret = "secret-key";
var base = FirebaseApp.getDatabaseByUrl(firebaseUrl, secret);
 var data = base.getData();
          for(var i in data) {
            Logger.log(data[i].firstName + ' ' + data[i].lastName);
          }
}

读取的数据显示在日志中。要检查日志,请单击查看日志**,或者只需使用“Control + Enter”。**

3.阅读特定记录

function getContact() {
  var firebaseUrl = "https://example-app.firebaseio.com/";
  var secret = "secret-key";
  var base = FirebaseApp.getDatabaseByUrl(firebaseUrl, secret);
  var contact = base.getData("Yash-Udasi");
  Logger.log(contact);
}

读取的数据显示在日志中。要检查日志,请单击查看日志**,或者只需使用“Control + Enter”。**

4.更新特定记录

function updateData() {
  var firebaseUrl = "https://example-app.firebaseio.com/";
  var secret = "secret-key";
  var base = FirebaseApp.getDatabaseByUrl(firebaseUrl, secret);
  base.updateData("Yash-Udasi/emailAddress", "yash.udasi@fyuff.com");
}