Web apps+ remotely using script

2019-09-13 20:30发布

问题:

I wrote a script that copies files to Google Drive. but I need to run it not from the script development page, I need to give it to the user, and I have to get from him a variable. How do I run the script remotely? If I add my script as a library to another script built into the table, then everything works, but I need the data to be passed from a google site or doGet() function.. Can I get string value and start a script from HTMLOutput?. Or any another solution of remotely starting of script(for example, pushing button on site) https://developers.google.com/apps-script/guides/web#deploying here is info about web apps, but I can't understand, how I can use it(

also i read this google apps script - web app doesn't seem to do anything . . but "The UI service was deprecated on December 11, 2014. To create user interfaces, use the HTML service instead." i can't understand what to do with this HTML service

回答1:

Html:

<body>
<input id="textField" type="text" size="4" onchange="">
<button onclick="cop()">Скопировать файлы</button>
<script>
function cop(){
var textField=document.getElementById("textField");
var text=textField.value;
google.script.run.copy(text);
//this was used for testing, it alerts what returnes from GS copy func
//google.script.run.withFailureHandler(alert).withSuccessHandler(alert).copy(text;
}
</script>
</body>

GS:

function doGet(e) {
  return HtmlService.createTemplateFromFile('Copyerka').evaluate();
}

function copy(text1){
  return "Recieved year= "+text1; 
}

https://developers.google.com/apps-script/guides/html/reference/run