如何通过API创建包含gs脚本的电子表格? [英] How can I create spreadsheet with included gs script by API?

查看:102
本文介绍了如何通过API创建包含gs脚本的电子表格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过Google引擎管理电子表格(由客户端通过API上传)。我创建了测试电子表格,通过.gs脚本中的函数扩展(如果通过在线编辑器添加它们,效果很好),但我不知道如何自动(可能通过API)将这样的.gs脚本应用于每个上传的电子表格。



此外,我不想通过发布它作为扩展(由于安全策略)来共享此.gs文件。



<更新:我也尝试复制现有的电子表格与工作GS脚本并通过API覆盖其电子表格数据(而不是上传新的) - 它被成功覆盖数据,但不幸丢失了GS脚本。详细信息在单独的(赏金)问题中描述:使用Google Java客户端复制电子表格后,自定义Google应用程序脚本不起作用 所以我已经甚至尝试使用纯HTTP方法进行复制,因为我认为这可能是Java SDK的问题,但它仍然不起作用,这意味着在服务帐户的谷歌方面存在一些问题(或者确实不清楚)。



毕竟我用另一种方法解决了问题。

首先,我将附有脚本的电子表格复制到我的服务帐户(正如我在此自定义Google应用中所述使用Google Java客户端复制电子表格后,脚本不起作用)主题)。 然后我使用google的oauth进行用户授权(本教程演示了如何 https://developers.google.com/identity/protocols/OAuth2WebServer#overview
然后以他的名义执行复制。



最后,这个文件位于他的私人驱动器中,这是该解决方案的最大缺点,但至少脚本是我的主要目标。



希望它有帮助;)


I'd like to manage spreadsheets (uploaded by a client via API) over google engine. I created test spreadsheet extended by functions in .gs script (which works great if I add them via online editor) but I do not know how to apply such a .gs script to every uploaded spreadsheet automatically (possibly via API).

Moreover, I do not want to share this .gs file by publishing it as an extension (because of security policies).

Updated: I also tried copying existing spreadsheet with working gs script and overwriting its spreadsheet data via API (instead of uploading new one) - it's overwritten data successfully but unfortunately lost gs script. Details are described in separate (bounty) question: Custom google app script doesn't work after copying spreadsheet with google java client

解决方案

So I've even tried copying using plain HTTP methods since I thought it might be a problem with Java SDK but it still didn't work which means that there is some problem at google side (or something is really unclear) with service accounts.

After all I solved the problem with another approach.

First I copy spreadsheet with script attached to it to my service account (as I described in this Custom google app script doesn't work after copying spreadsheet with google java client topic). The file is copied with broken script.

Then I make user authorize using google's oauth (this tutorial shows how https://developers.google.com/identity/protocols/OAuth2WebServer#overview) And then on his behalf I perform copying.

Finally the file is on his private drive which is the biggest downside of this solution but at least the script works which was my main goal.

Hope it helps ;)

这篇关于如何通过API创建包含gs脚本的电子表格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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