google 来自应用引擎的应用

google apps from app engine

我想根据存储在用户 Google 驱动器上的(Google 文档)模板和一些 XML 保存的数据生成 Google Apps 文档Google App Engine 上的 servlet 运行ning。

最好是我想运行尽可能多的上GAE。是否可以在 GAE 上 运行 Apps Service APIs 或在 GAE 上 download/manipulate Google doc?我没能找到合适的东西

显然,一种替代方法是使用 Apps 脚本实现合并功能,将 XML 作为参数传输,并通过来自 GAE 的 http 启动脚本,但相比之下,它似乎有些笨拙。

编辑: 具体来说,我正在寻找要在 GAE 中实现的 replaceText 脚本功能,如下面的 Apps 脚本片段所示。剩余代码通过 Drive/Mail API 支持,我猜..

// Get document template, copy it as a new temp doc, and save the Doc’s id
var copyId   = DocsList.getFileById(providedTemplateId)
              .makeCopy('My-title')
              .getId();
var copyDoc  = DocumentApp.openById(copyId);
var copyBody = copyDoc.getActiveSection();

// Replace place holder keys,  
copyBody.replaceText("CustomerAddressee", fullName);
var todaysDate =  Utilities.formatDate(new Date(), "GMT+2", "dd/MM-yyyy"); 
copyBody.replaceText("DateToday", todaysDate);

// Save and close the temporary document
copyDoc.saveAndClose();

// Convert temporary document to PDF by using the getAs blob conversion
var pdf = DocsList.getFileById(copyId).getAs("application/pdf"); 

// Attach PDF and send the email
MailApp.sendEmail({
    to: email_address, 
    subject: "Proposal", 
    htmlBody: "Hi,<br><br>Here is my file :)<br>Enjoy!<br><br>Regards Tony", 
    attachments: pdf}); 

Apps 脚本几乎依赖于已发布的标准 Google API。行为越来越熟悉。

显然应用程序脚本是基于 js 而不是 gae。除了与脚本相关的 API 运行 之外,所有 API 都可在标准 gae 客户端运行时中使用。

这里没有可检查的代码,所以恐怕我只有通用的答案。

我现在知道可以通过使用 Google Drive API to export (download) the Google Apps Doc file as PDF (or other formats) to GAE, and do simple replace-text editing using e.g. the iText library

来解决

如您所知,应用程序脚本目前是唯一可以访问 api 以修改 google 文档的脚本。除非您导出为另一种格式(如 pdf 或 .doc),然后使用可以修改这些格式的库,然后重新上传要求转换为 google 文档原生格式的新文件,否则所有其他方法都无法做到这一点,在某些情况下会失去一些 format/comments/named 范围和其他 google 文档功能。所以就像你说的,如果你必须使用 google 文档 api 你必须调用应用程序脚本(作为内容服务)。另请注意,您显示的示例应用程序脚本代码是旧的并且使用了 deptecated docsList,因此您需要将其移植到驱动器 api.