Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google apps script 表单提交谷歌云打印_Google Apps Script_Google Sheets_Google Forms_Google Cloud Print - Fatal编程技术网

Google apps script 表单提交谷歌云打印

Google apps script 表单提交谷歌云打印,google-apps-script,google-sheets,google-forms,google-cloud-print,Google Apps Script,Google Sheets,Google Forms,Google Cloud Print,在提交Google表单时,我需要一些帮助来创建脚本 表单提交后,脚本会自动将Google电子表格打印到基于Google云的打印机上,而无需打开打印对话框窗口 我已经通读了 脚本背后的想法很简单: 用户填写表格 然后提交表格 脚本使用用户输入的信息更新单元格 脚本然后打印到谷歌云打印机 装运标签准备好了 下面的脚本将打印票据,但如何将打印机功能添加到POST请求 到目前为止,我掌握的代码是: function onsubmit(e) { var pid = "123456789"; //pla

在提交Google表单时,我需要一些帮助来创建脚本

表单提交后,脚本会自动将Google电子表格打印到基于Google云的打印机上,而无需打开打印对话框窗口

我已经通读了

脚本背后的想法很简单:

  • 用户填写表格
  • 然后提交表格
  • 脚本使用用户输入的信息更新单元格
  • 脚本然后打印到谷歌云打印机
  • 装运标签准备好了
下面的脚本将打印票据,但如何将打印机功能添加到POST请求

到目前为止,我掌握的代码是:

function onsubmit(e) {
var pid = "123456789"; //place printer id here
var sheetid = "123456789"; //place sheet id here
var ss = SpreadsheetApp.getActiveSpreadsheet();  
var info = ss.getSheetByName('Form responses 1');  
var lastRow = info.getLastRow();  
var sheet = SpreadsheetApp.setActiveSheet(ss.getSheetByName('TICKET'))  

authorize();
var url = "https://www.google.com/cloudprint/submit?printerid="+pid+"&contentType=google.spreadsheet&content="+sheetid+"&title=PrintingTicket";
var options = {
  method: "post",
  oAuthServiceName : "print",
  oAuthUseToken : "always"
   };
info.hideSheet();
var response = UrlFetchApp.fetch(url, options);
return Utilities.jsonParse(response.getContentText());
}

function authorize() {
var oauthConfig = UrlFetchApp.addOAuthService("print");
var scope = "https://www.googleapis.com/auth/cloudprint";
oauthConfig.setConsumerKey("anonymous");
oauthConfig.setConsumerSecret("anonymous");
oauthConfig.setRequestTokenUrl("https://www.google.com/accounts/OAuthGetRequestToken?scope="+scope);
oauthConfig.setAuthorizationUrl("https://accounts.google.com/OAuthAuthorizeToken");    
oauthConfig.setAccessTokenUrl("https://www.google.com/accounts/OAuthGetAccessToken");  
}

这并不是非常简单,因为
gcpweb元素
是用HTML/JS编写的,而googleapps脚本就是JS。但这应该是可能的。我已经能够从以下网站成功打印电子表格(向下滚动到打印对话框并将电子表格ID放入),我已经更新了示例代码以包含“post”方法,但它产生了一个错误:返回代码403的请求失败。截断的服务器响应:需要用户凭据需要用户凭据错误。。。(使用muteHttpExceptions选项检查完整响应)。(第20行,文件“代码”)非常感谢任何帮助。任何人都可以帮助发送打印机功能吗?