提供什么建议恩里克,这里的例子是small webapp,增加了文本到publicly viewable document我自己的(它并不需要是除了这里任何人都可以查看它的工作原理大众!)
我写的它使用了UiApp但你当然可以使用HTMLService如果你喜欢...
该应用程序运行作为我,但任何人甚至是匿名访问。
// publicly viewable test doc url : https://docs.google.com/document/d/1THzBTURxGr2CdUmcZ7i2zD-RM8I3im2JCSHI3BHlkeM/edit
function doGet(){
var app = UiApp.createApplication().setTitle('docEdit');
var panel = app.createAbsolutePanel().setSize('100%','100%').setStyleAttributes({'padding':'40px','backgroundColor':'lightBlue'});
var text = app.createTextArea().setName('text').setPixelSize(500,300);
var grid = app.createFlexTable().setId('grid');
grid.setText(0,0,'Add your text').setWidget(1,0,text);
var handler = app.createServerHandler('writeText').addCallbackElement(panel);
grid.setWidget(2,0,app.createButton('update document',handler).setId('btn'));
app.add(panel.add(grid));
return app;
}
function writeText(e){
var doc = DocumentApp.openById('1THzBTURxGr2CdUmcZ7i2zD-RM8I3im2JCSHI3BHlkeM');
var now = Utilities.formatDate(new Date(),Session.getScriptTimeZone(),'MMM/dd/yyyy @ hh:mm:ss');
var body = doc.getBody();
body.appendParagraph('Append text on '+now+' : '+e.parameter.text);
doc.saveAndClose();
var app = UiApp.getActiveApplication();
var grid = app.getElementById('grid');
grid.setWidget(3,0,app.createHTML('Thanks,<br>Your text has been added to the document'));
app.getElementById('btn').setEnabled(false).setHTML('Button disabled');
return app;
}
它的工作原理,但我得到'xmlhttprequest无法加载'access-control-allow-origin'错误。你知道脚本应该返回给客户吗? – sangil 2014-11-03 15:00:38
你不应该有这个问题。你能分享一个问题的例子(访问一个Apps脚本公共网址)吗? – 2014-11-03 16:16:35
没关系,我的坏。我从本地运行客户端而不是实际的IP地址 – sangil 2014-11-03 16:25:30