Google apps script 从Google Sheet exportLink[';应用程序/pdf';]获取UrlFetch不返回pdf数据

Google apps script 从Google Sheet exportLink[';应用程序/pdf';]获取UrlFetch不返回pdf数据,google-apps-script,google-sheets,Google Apps Script,Google Sheets,我创建并发送一封定期电子邮件,作为谷歌工作表的更新。出于各种客户原因,这有3种方式,作为工作表的链接和附件(PDF和XLSX) 直到最近,这种方法才奏效。XSLX附件仍然有效,但PDF不再作为对UrlFetch的响应发送到file.exportLinks('application/PDF')url。无论请求头是什么,它总是以内容类型返回:“application/vnd.openxmlformats officedocument.spreadsheetml.sheet” 我在这里遗漏了什么其他未

我创建并发送一封定期电子邮件,作为谷歌工作表的更新。出于各种客户原因,这有3种方式,作为工作表的链接和附件(
PDF
XLSX

直到最近,这种方法才奏效。XSLX附件仍然有效,但PDF不再作为对
UrlFetch
的响应发送到
file.exportLinks('application/PDF')
url。无论请求头是什么,它总是以
内容类型返回:“application/vnd.openxmlformats officedocument.spreadsheetml.sheet”

我在这里遗漏了什么其他未记录的变化吗

function exportAsPDF(spreadsheetId) {
  spreadsheetId = spreadsheetId || 'SECRET_ID';

  var file = Drive.Files.get(spreadsheetId),
      url = file.exportLinks['application/pdf'];

  url += '&format=pdf&size=7&fzr=true&portrait=true&fitw=true&gid=0&gridlines=false&printtitle=false&sheetnames=false&pagenum=UNDEFINED&attachment=true'

  var token = ScriptApp.getOAuthToken(),
      response = UrlFetchApp.fetch(url, {
          headers: {
              'Authorization': 'Bearer ' +  token
          }
      });

  var headers = response.getAllHeaders(); // revealing content-type returned isn't pdf
  var pdfBlob = response.getBlob().getAs('application/pdf');      
  var pdfString = pdfBlob.getDataAsString(); // this naturally throws an error

  return response.getBlob(); // this returns to the send mail script
}

我可以使用来自的实用程序获取PDF

该工作脚本将电子表格的编辑URL修改为导出URL,如下所示:

https://docs.google.com/spreadsheets/d/<%SS-ID%>/export?exportFormat=pdf...
https://docs.google.com/spreadsheets/d//export?exportFormat=pdf...
高级驱动器服务提供的导出URL格式如下:

https://docs.google.com/spreadsheets/export?id=<%SS-ID%>&exportFormat=pdf...
https://docs.google.com/spreadsheets/export?id=&exportFormat=pdf...
我希望
exportLinks
提供的URL比工作脚本中的hack更可靠。显然不是


这一点已被提出为。启动它以接收更新。

Drive
是我将Google Advanced Drive API映射到的正在工作的内容-有趣的是,在工作表转换为新工作表之前,我曾使用该URL停止工作:/