user8087383
user8087383

Reputation:

Import firebase DB values into googlesheet

I have a project which uses firebase database to store data, the structure of my firebase DB table is as follows:

table_name
   | abc12345677890xxxxxxxxx
       | key_namea: 45852
       | key_nameb: "string characters"
       | key_namec: 45852
       | key_named: "string characters"
       | key_named: "string characters"
       | secondleveldeep
          | key_name: value
          | key_name: value

I looked into googlesheet api and came up with a function thats meant to get the data but every time i run into the following error

"Error: We're sorry, a server error occurred. Please wait a bit and try again. (line 272, file "Code", project"

function getData() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheetByName('sheet1');
  var range = sheet.getRange(1,1,5000,1); // unclear about this
  var data = getFirebaseBase('table_name');
  Logger.log(data);
  range.setValues(JSON.parse(data));  
}

function getFirebaseBase (data) {
  var firebaseUrl  = 'https:xxx.firebaseio.com';
  var secret = 'abcXXXX...';
  var base = FirebaseApp.getDatabaseByUrl(firebaseUrl, secret);
  var result = base.getData(data);
  return result;
}

Has anyone successfully imported data from firebase into googlesheet (NOT INTERESTED IN THE REVERSE), if so please could you shed some light what i'm missing or not doing right.

Upvotes: 0

Views: 310

Answers (1)

Doug Stevenson
Doug Stevenson

Reputation: 317322

You can update your spreadsheet in real time with every change to your database using a Cloud Functions database trigger.

It's a somewhat involved process to set up, but you can see this in action in a tweet with an animated GIF.

Click through to this gist for instructions and source code. This example is a minimal simple example, and you'll probably want to extend that to your specific use case.

You can also go the other direction if you become interested in that.

Upvotes: 1

Related Questions