从自定义Google小工具调用Google Apps脚本小工具? [英] Calling Google Apps Script Gadget from custom Google Gadget?

查看:183
本文介绍了从自定义Google小工具调用Google Apps脚本小工具?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用带有嵌入Google Apps脚本的Google Site,我使用JDBC显示来自数据库的一些数据。 Google Apps脚本使用 doGet 来加载HTML页面:

 函数doGet(){
return HtmlService.createHtmlOutputFromFile('index');

... index.html页面依次调用我的Apps中的函数获取一些数据库数据的脚本:

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

调用 mySuccesshandler 时,使用JQuery的数据。



这有效。但是,嵌入式Google Apps脚本具有静态定义的高度。 SO上的帖子建议开发一个自定义当内容发生变化时,Google Gadget会动态调整大小

但我找不到任何示例,或者确认我可以将我当前的Google Apps脚本移植到我自己的小工具中。有关使用远程内容的文档未提及数据库。



我尝试将调用放到我的应用程序脚本的小工具XML文件中:

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

但是,不能调用run undefined 。那么有没有什么办法可以从定制的Google Widget中调用GAS?

解决方案

你不能像这样混合它们,它们是不同和断开连接(例如,xml小工具如何知道哪些应用程序脚本在您的尝试中调用?)。
最简单的方法是仅将apps脚本用作doGet中contentService的json等数据提供者。从xml小工具中,您可以使用ajax进入apps脚本发布的url&任何需要的参数。
为了避免认证麻烦,发布脚本以匿名访问的方式运行。


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?

解决方案

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.

这篇关于从自定义Google小工具调用Google Apps脚本小工具?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆