【发布时间】:2015-09-15 23:28:30
【问题描述】:
我创建并定期发送一封电子邮件,作为来自 Google 表格的更新。出于各种客户原因,这是通过 3 种方式完成的,作为指向工作表的链接和作为附件(PDF 和 XLSX)。
这直到最近才起作用。 XSLX 附件仍然有效,但 PDF 不再作为对UrlFetch 的响应发送到file.exportLinks('application/pdf') url。无论请求头是什么,它总是返回为Content-Type: "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
}
【问题讨论】:
-
Drive是我将 Google Advanced Drive API 映射到的对象
标签: google-apps-script google-sheets