简体   繁体   中英

Google Sheet update data from my server

I create a Google Sheet add-on but now I need to update the sheet when there is new update on my server. I found there are 2 options.

  1. use installable trigger to periodically pull values from my server.
  2. use form submit trigger. I'm not sure whether this can be used for pulling data.

Which is the best option to pull data and update to Google Sheet for a published add-on?

Google just released Cloud Messaging Pub/Sub. This is a tool that covers exactly what you are trying to accomplish.

https://cloud.google.com/pubsub/overview

Pub/Sub is an API that is designed for application to application messaging. You need to set up your script as a push webhook endpoint. It isn't obvious, nor documented, but I figured it out through exploration. This is needed to set up you add-ons and server for push notifications instead of using pulling.

  1. Publish your script as a webapp.
  2. Deploy it to the Chrome Store. You do not need to publish so you can leave it in draft.
  3. Get the published WebApp URL. It will look something like:

     https://script.google.com/macros/s/AKfycbx7STHODJlW...EjvowTaO0mmZ3TA9Xsdq1/exec 
  4. Go back the the Developer Console from your script and choose Push under API & Auth.

  5. Add the domain specific URL without the trailing 'exec' in my case :

     https://script.google.com/macros/s/AKfycbx7STHODJlW...EjvowTaO0mmZ3TA9Xsdq1/ 

The form submit trigger only happens when someone submits a Google Form. I have no idea when and by what event your server is being updated.

If your server can submit an HTTP Request, you could use a Google Sheets API.

https://developers.google.com/google-apps/spreadsheets/

The installable time trigger would be a lot easier.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM