将外部 javascript 导入谷歌应用程序脚本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18646554/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 12:44:44  来源:igfitidea点击:

importing external javascript to google apps script

javascriptgoogle-apps-scripttrello

提问by dixkin

I am trying to use Trello from a Google Spreadsheet (Google Docs) and am not sure how to import/reference/link the javascript files required to use their library. My only other option is using their REST API directly (fine, but I'd rather use their js helper classes).

我正在尝试从 Google 电子表格(Google 文档)中使用 Trello,但不确定如何导入/引用/链接使用其库所需的 javascript 文件。我唯一的其他选择是直接使用他们的 REST API(很好,但我宁愿使用他们的 js 帮助程序类)。

This is what Trello needs us to use:

这就是 Trello 需要我们使用的:

 <script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
 <script src="https://api.trello.com/1/client.js?key=substitutewithyourapplicationkey"</script>

How would I import/include these in a Google Apps Script?

我如何将这些导入/包含在 Google Apps 脚本中?

THANKS!!!

谢谢!!!

回答by owyongsk

Based on the answer here by Cameron Roberts, you can use the eval() function on the appscript UrlFetchApp function.

根据Cameron Roberts的回答,您可以在 appscript UrlFetchApp 函数上使用 eval() 函数。

eval(UrlFetchApp.fetch('http://path.to/external/javascript.js').getContentText());

回答by kahmed

you actually can . In the script project create another new file and simply just paste the JavaScript library copying from the source and save it then start referencing it from other file. It is that simple.

你实际上可以。在脚本项目中创建另一个新文件,只需粘贴从源代码复制的 JavaScript 库并保存,然后开始从其他文件引用它。就是这么简单。

Or you can create another project with the .js lib and publish it and reference that script from the caller project, I wont do that unless that needs to be shared in multiple projects.

或者您可以使用 .js 库创建另一个项目并发布它并从调用者项目中引用该脚本,除非需要在多个项目中共享,否则我不会这样做。

回答by Mogsdad

You cannot use external javascript libraries this way in Google Apps Script. (You cando so in html files used with the HtmlService. Since so much of Trello is client-side anyway, this may be just what you need.)

您不能在 Google Apps 脚本中以这种方式使用外部 javascript 库。(您可以在与HtmlService一起使用的 html 文件中执行此操作。无论如何,Trello 的大部分内容都是客户端,这可能正是您所需要的。)

In server-side apps script, you should be able to access the library code using the technique from this answer. It doesn't say, but I'd imagine that you would put that evaloutside of all functions in your script, to make the objects in the library available to the rest of your code.

在服务器端应用程序脚本中,您应该能够使用此答案中的技术访问库代码。它没有说,但我想你会将它放在eval脚本中的所有函数之外,以使库中的对象可用于其余代码。

回答by Zig Mandel

Download them and put them in the script. The rest api is easy to use. Ive used trello rest from appscript.

下载它们并将它们放入脚本中。其余的api很容易使用。我使用过 appscript 中的 trello rest。

回答by youssef

Yes you can use JavasSript libraries in Google script. Copy all content of the libraries JavaScript and post it in new GS file.

是的,您可以在 Google 脚本中使用 JavasSript 库。复制库 JavaScript 的所有内容并将其发布到新的 GS 文件中。

回答by Andres9619

You can try this 2 options:

你可以试试这两个选项:

Hope this helps

希望这可以帮助