Calling Google Apps Script Gadget from custom Google Gadget?

倾然丶 夕夏残阳落幕 提交于 2019-12-12 04:43:38

问题


Using a Google Site with an embedded Google Apps Script, I'm displaying some data from a database using JDBC. The Google Apps Script uses doGet to load an HTML page:

function doGet() {
   return HtmlService.createHtmlOutputFromFile('index');
}

...the index.html page in turn calls a function in my Apps Script to get some database data:

google.script.run.withSuccessHandler(mySuccessHandler).getSomeDBData();

When the mySuccesshandler is called, I render the data with the JQuery.

This works. However, embedded Google Apps Scripts have a statically defined height. A post on SO suggested developing a custom Google Gadget which dynamically resizes when content changes.

But I can't find any examples, or confirmation that I can port my current Google Apps Script to my own Gadget. The documentation on working with remote content doesn't mention databases.

I tried placing the call to my App Script in the Gadget XML file:

 google.script.run.withSuccessHandler(mySuccessHandler).getSomeDBData();

However, this failed with cannot call run of undefined. So is there any way I can call a GAS from a custom Google Widget?


回答1:


You cant mix them like that, they are different and disconnected (for example how would the xml gadget know which apps script to call in your attempt?). The easiest would be to use the apps script solely as a data provider like json from a contentService in doGet. From the xml gadget you do an ajax get to the apps script published url & any needed parameters. To avoid auth hassles publish script to run as you with anonymous access.



来源:https://stackoverflow.com/questions/22878901/calling-google-apps-script-gadget-from-custom-google-gadget

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!