GoogleJsonResponseException: API call to drive.files.insert failed with error: Bad Request
GoogleJsonResponseException: API call to drive.files.insert failed with error: Bad Request
我正在尝试触发脚本从 Gmail 电子邮件中复制附加的 excel 文件并将其复制到 google sheets sheet 中。应复制任何带有“TO PROCESS”标签的电子邮件。我收到此错误消息:
GoogleJsonResponseException: API call to drive.files.insert failed with error: Bad Request
错误发生在以下行:
var convertedSpreadsheetId = Drive.Files.insert({mimeType: MimeType.GOOGLE_SHEETS}, xlsxBlob).id; //Converts Excel to "Google Sheet" in google drive and gets file Id
完整代码如下:
function emailTrigger() {
var label = GmailApp.getUserLabelByName("TO PROCESS");
if(label != null){
var threads = label.getThreads();
for (var i=0; i<threads.length; i++) {
getExcelFile(threads[i]);
//Process them in the order received
threads[i].removeLabel(label);
}
}
}
function getExcelFile(thread)
{
//Function to pull Weekly Schedule Excel file from Janettas email and update phone spreadsheet and calendar
var messages = thread.getMessages(); //pulls messages in first thread
var len = messages.length; //Gets number of messages in first thread
var message = messages[len-1] //get first message in given thread
var attachments = message.getAttachments(); // Get attachment of first message
//Steps to process the attachement
var xlsxBlob = attachments[0]; // Is supposes that attachments[0] is the blob of xlsx file.
var convertedSpreadsheetId = Drive.Files.insert({mimeType: MimeType.GOOGLE_SHEETS}, xlsxBlob).id; //Converts Excel to "Google Sheet" in google drive and gets file Id
var filename = xlsxBlob.getName(); //gets the converted files file name
var tabName = filename.substring(13).slice(0,filename.length-18); // process the filename string into just the date to be Tab Name
var sheet = SpreadsheetApp.openById(convertedSpreadsheetId).getSheets()[0]; // Location of converted Excel file -> now google sheet
}
发生错误是因为特定的 excel 电子表格已加密。代码没有问题,可以按预期使用。
我正在尝试触发脚本从 Gmail 电子邮件中复制附加的 excel 文件并将其复制到 google sheets sheet 中。应复制任何带有“TO PROCESS”标签的电子邮件。我收到此错误消息:
GoogleJsonResponseException: API call to drive.files.insert failed with error: Bad Request
错误发生在以下行:
var convertedSpreadsheetId = Drive.Files.insert({mimeType: MimeType.GOOGLE_SHEETS}, xlsxBlob).id; //Converts Excel to "Google Sheet" in google drive and gets file Id
完整代码如下:
function emailTrigger() {
var label = GmailApp.getUserLabelByName("TO PROCESS");
if(label != null){
var threads = label.getThreads();
for (var i=0; i<threads.length; i++) {
getExcelFile(threads[i]);
//Process them in the order received
threads[i].removeLabel(label);
}
}
}
function getExcelFile(thread)
{
//Function to pull Weekly Schedule Excel file from Janettas email and update phone spreadsheet and calendar
var messages = thread.getMessages(); //pulls messages in first thread
var len = messages.length; //Gets number of messages in first thread
var message = messages[len-1] //get first message in given thread
var attachments = message.getAttachments(); // Get attachment of first message
//Steps to process the attachement
var xlsxBlob = attachments[0]; // Is supposes that attachments[0] is the blob of xlsx file.
var convertedSpreadsheetId = Drive.Files.insert({mimeType: MimeType.GOOGLE_SHEETS}, xlsxBlob).id; //Converts Excel to "Google Sheet" in google drive and gets file Id
var filename = xlsxBlob.getName(); //gets the converted files file name
var tabName = filename.substring(13).slice(0,filename.length-18); // process the filename string into just the date to be Tab Name
var sheet = SpreadsheetApp.openById(convertedSpreadsheetId).getSheets()[0]; // Location of converted Excel file -> now google sheet
}
发生错误是因为特定的 excel 电子表格已加密。代码没有问题,可以按预期使用。