将容器绑定的Google Apps脚本部署为Web App [英] Deploying container-bound Google Apps Script as Web App

查看:108
本文介绍了将容器绑定的Google Apps脚本部署为Web App的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Apps脚本中的Google Docs API创建了一个拼写检查器(仅用于扩展Google Doc功能的脚本),并且我不想将此服务提供给将其下载为Web的用户应用。问题是,当我在脚本编辑器中创建了我的(容器绑定的)脚本时,它仅在我创建它的Google文档中可用 - 也就是说,如果我打开一个新文档,则无法使用该脚本。



如果我部署为Web应用程序,将其提供给所有人并粘贴给定的URL,则会收到一条错误消息,指出脚本需要一个名为doGet的函数),它不在我的脚本中。



如何将脚本发布为常规Web应用程序?

核心功能将被部署为一个Web应用程序,一个简单的容器绑定脚本将提供一个接口来调用Web应用程序。



由于Web应用程序未绑定到文档,因此您可能需要遵循以下方案:

<$ (e.parameter.docId){
doStuff(DocumentApp.openById(e.parameter.docId));函数doGet(e){
if(e.parameter.docId){
doStuff(DocumentApp.openById(e.parameter.docId));


$ / code $ / pre

现在,当你部署应用程序时,你会得到一个链接使您可以访问该功能。



在容器绑定的脚本中,您可以添加一些链接到网页的UI(例如,侧面板中的Anchor元素)应用程序使用适当的参数
$ b $ pre $ ScriptApp.getService()。getUrl()+?docId =+ DocumentApp.getActiveDocument() .getId()

或使用 UrlFetchApp 获取结果并将其显示在UI中。



不幸的是,这与自动在所有文档中添加功能不同,而是在每个要添加功能的文档中只安装一个相对轻量级的钩子,而不是完整的脚本。
我不知道有任何方法可以实现这一点。请注意,制作文档副本时,副本将包含其所有脚本,以便为需要附加功能的文档创建模板。尽管如果你想混合和匹配多个脚本,这可能会变得很棘手。



我的方法的优点是,如果您修改了核心功能,则更改立即可用所有的文件都可以使用它,而不需要更新脚本。另一方面,如果容器脚本需要与UI进行大量交互,它可能会变得复杂并降低将它分成两个脚本的有用性。


I'm creating a spellchecker using the Google Docs API in an Apps Script (just a script that extends the functionality of a Google Doc), and I wan't to make this service available to users whom download it as a Web App. Problem is that when I've made my (Container-bound) script in the script editor, it is only available in the Google Document through which I created it - that is, if i open a new document, I cannot use the script.

If I "Deploy as Web App", make it available to everyone and paste the given URL, I get an error message saying that the script needs a function called doGet(), which is not in my script.

How do I go about to publish my script as a regular web app?

解决方案

I would proceed by creating two scripts: the core functionality would be deployed as a Web App and a simple container-bound script would offer an interface to call the Web App.

Since the Web App is not bound to a document you may want to follow this scheme:

function doGet(e){
    if(e.parameter.docId){
        doStuff(DocumentApp.openById(e.parameter.docId));
    }
}

Now when you deploy the app you will get a link that gives you access to the functionality.

From the container-bound script you can add some UI (e.g. an Anchor element in a side-panel) that links to the web app with the appropriate parameters

ScriptApp.getService().getUrl() + "?docId=" + DocumentApp.getActiveDocument().getId()

or use UrlFetchApp to get the results and display them in the UI.

Unfortunately this is not the same as adding the functionality across all your documents automatically, but rather a way to install only a relatively lightweight hook in each document where you want to add the functionality, instead of the full script. I am not aware of any method that can achieve that. Note that when you make a copy of a document, the copy will contain all its scripts so you can create a template for documents that need the additional functionality. This can get ackward though if you wish to mix and match multiple scripts.

The advantage of my method is that if you modify the core functionality, the change is immediately available to all your documents making use of it, with no need to update their scripts. On the other hand if the container-script needs to interact heavily with the UI it may get complicate and reduce the usefulness of separating it in two scripts.

这篇关于将容器绑定的Google Apps脚本部署为Web App的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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