我正在尝试借助示例Firebase from Google Script来从Google Sheets编写Firebase Realtime Database,在该示例中,密钥是通过dataToImport[title + '-' + sub_title]
的组合编写的
但是我想用编写Firebase Realtime Database时生成的自动生成的密钥替换它
WriteFirebase.gs
function writeDataToFirebase() {
var ss = SpreadsheetApp.openById("xxxxxxxxxxxxxxxxxxxxx");
var sheet = ss.getSheets()[0];
var data = sheet.getDataRange().getValues();
var dataToImport = {};
for(var i = 1; i < data.length; i++) {
var title = data[i][0];
var sub_title = data[i][1];
dataToImport[title + '-' + sub_title] = {
title:title,
sub_title:sub_title,
description:data[i][2],
posted_by:data[i][3],
image_url:data[i][4],
};
}
var firebaseUrl = "https://script-examples.firebaseio.com/";
var secret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
var base = FirebaseApp.getDatabaseByUrl(firebaseUrl, secret);
base.setData("", dataToImport);
}