function writeDataToFirebase() {
var ss = SpreadsheetApp.openById("1LACsj0s3syAa9gvORdRWBhJ_YcXHybjQfHPgw3TLQ6g");
var sheet = ss.getSheets()[0];
var data = sheet.getDataRange().getValues();
var dataToImport = {};
for(var i = 1; i < data.length; i++) {
var firstName = data[i][0];
var lastName = data[i][1];
dataToImport[firstName + '-' + lastName] = {
firstName:firstName,
lastName:lastName,
emailAddress:data[i][2],
semester:data[i][4],
department:data[i][5],
};
}
var firebaseUrl = "https://example-app.firebaseio.com/";
var secret = "secret-key";
var base = FirebaseApp.getDatabaseByUrl(firebaseUrl, secret);
base.setData("", dataToImport);
}
Replace the spreadsheet ID and the firebaseURL and the secret key.
To see the database go to the Firebase dashboard and Click on the Database you can view the database.
function myFunction(){
var firebaseUrl = "https://example-app.firebaseio.com/";
var secret = "secret-key";
var base = FirebaseApp.getDatabaseByUrl(firebaseUrl, secret);
base.setData("test", "Hello Firebase");
}
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);
}
}
The data read is displayed in the Logs. To check logs click on click on View → Logs or simply use Control + Enter.
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);
}
The data read is displayed in the Logs. To check logs click on click on View → Logs or simply use Control + Enter.
function updateData() {
var firebaseUrl = "https://example-app.firebaseio.com/";
var secret = "secret-key";
var base = FirebaseApp.getDatabaseByUrl(firebaseUrl, secret);
base.updateData("Yash-Udasi/emailAddress", "[email protected]");
}