Firebase JSON REST access library for Apps Script

The BigQuiz app uses Firebase for keep track of the question, category and game scores of individual players. In Firebase custom authentication with goa I showed how to use Goa to manage authentication for Firebase. This firebase access library works with goa, or you can use a different JWT generator if you aleady have one.

Why Firebase?

I had originally planned to use the JSON API for Google Game Play Services but I really think Google have got it all wrong for this API.

The Game play services API is extremely complicated to set up. There are multiple consoles and credentials, and registrations and thumbnail images and other boring stuff to go through - even if you just want to try it out - I think many people who may otherwise go on to use it, are going to be put off by this and just do something else - as I did.

There is a $25 registration fee to get started. Even if you just want to have a look at it to see if you want to use it. Surely marketing 101 says that you don't charge people to have a look at something. By all means charge if it gets used, but not just to look.

If I'd persevered and swallowed the registration charge and worked through all the complex console stuff, then I probably would have got game play services to work, but a simple solution with Firebase is just fine for my demo BigQuiz app.

the data at the given location is partially updated with the values inthe partial object

remove

handle.remove ('players/112066118406610145134')

Remove the data at the given location. this would remove all data for the selected player.

removeAll

handle.removeAll()

remove all the data in the database

setAuthData

handle.setAuthData (goa)

set the root and key using a goa object

setAuthData

handle.setAuthData ({key:jwt,root:"https://bigquiz.firebase.io"})

if you are not using goa, you can set this using a custom object

setPromiseMode

handle.setPromiseMode(true)

return promises instead of results. More on that later

Responses

All data requests return an object with these properties. Exponential backoff is automatically applied to all requests.

property

description

ok

true if everything has worked fine

data

the data returned from firebase

response

the httprresponse from the request

path

the url that was fetched from

Promise mode

By default, a request like this will result in a response as above.

var result = handle.get();

However it is possible to use Promise mode in order to return a promise rather than a result. This can sometimes be more convenient as described in Using es6 promises server side in Apps Script, although since Apps Script is currently not asynchonous, there are no performance benefits currently (but preparing for the future is never a bad thing).