How to listen for realtime updates in Firebase Clo

2019-08-23 02:18发布

问题:

In the official documentation of Firebase, we can do it with https://firebase.google.com/docs/firestore/query-data/listen

let doc = db.collection('cities').doc('SF');

let observer = doc.onSnapshot(docSnapshot => {
  console.log(`Received doc snapshot: ${docSnapshot}`);
  // ...
}, err => {
  console.log(`Encountered error: ${err}`);
});

But how can we do it with Google Apps Script?

回答1:

To run an Apps Script on a event (like a data update) implies using triggers. Unfortunately, at the moment there are no Apps Script triggers supporting Firebase.

However, you can include JavaScript code in the HTML file attached to your Apps Script file and deploy it as a Web App.