从云端硬盘文件夹自动化Google云打印

时间:2017-08-10 15:59:59

标签: javascript google-apps-script google-cloud-print

作为序言,我通过应用程序脚本运行Google云打印。我有OAuth2设置,我能够设置一个云打印API,将我的Google云端硬盘中的单个文件打印到我的云打印上的打印机。

话虽如此,我正在寻找一种自动化脚本的方法,以便当文档放置在我的Google云端硬盘的特定文件夹中时,它会自动打印。我在周围搜索过,却找不到类似的东西。这是我的起点(这是一篇非常有用的教程):



function printGoogleDocument(docId, docTitle) {
  // For notes on ticket options see https://developers.google.com/cloud-print/docs/cdd?hl=en
  var ticket = {
    version: "1.0",
    print: {
      color: {
        type: "STANDARD_COLOR"
      },
      duplex: {
        type: "NO_DUPLEX"
      },
    }
  };

  var payload = {
    "printerid": myPrinterId,
    "content": docId,
    "title": docTitle,
    "contentType": "google.kix", // allows you to print google docs
    "ticket": JSON.stringify(ticket),
  };

  var response = UrlFetchApp.fetch('https://www.google.com/cloudprint/submit', {
    method: "POST",
    payload: payload,
    headers: {
      Authorization: 'Bearer ' + getCloudPrintService().getAccessToken()
    },
    "muteHttpExceptions": true
  });

  // If successful, should show a job here: https://www.google.com/cloudprint/#jobs

  response = JSON.parse(response);
  if (response.success) {
    Logger.log("%s", response.message);
  } else {
    Logger.log("Error Code: %s %s", response.errorCode, response.message);
  }
  return response;
}




因此,当我填写我的docID和PrinterID时,它适用于单个文档。但就像我说的那样,我试图根据Drive文件夹中的新文件自动执行此操作。有什么建议吗?

0 个答案:

没有答案