Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/5.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 Gmail应用程序脚本:基于Google Drive URL的附件_Google Apps Script_Gmail_Google Sheets - Fatal编程技术网

Google apps script Gmail应用程序脚本:基于Google Drive URL的附件

Google apps script Gmail应用程序脚本:基于Google Drive URL的附件,google-apps-script,gmail,google-sheets,Google Apps Script,Gmail,Google Sheets,我使用的是我在这里找到的邮件合并脚本,但是我很难找到正确的类来附加文件(第14行和第15行) 我尝试了附件函数的一些变体,但每次都会出错。行对应于Google工作表中的列,行[11]是Google drive中图像的URL。以下是脚本的工作示例:您有两个错误: 范围定义只有一列 附件的参数应该是一个blob数组 还要注意,url必须有效,并且文件必须公开共享:例如: https://drive.google.com/uc?export=view&id=0B3qSFd3iikE3TUFF

我使用的是我在这里找到的邮件合并脚本,但是我很难找到正确的类来附加文件(第14行和第15行)


我尝试了附件函数的一些变体,但每次都会出错。行对应于Google工作表中的列,行[11]是Google drive中图像的URL。

以下是脚本的工作示例:您有两个错误:

  • 范围定义只有一列
  • 附件的参数应该是一个blob数组

  • 还要注意,url必须有效,并且文件必须公开共享:例如:

    https://drive.google.com/uc?export=view&id=0B3qSFd3iikE3TUFFLTc5MDE0MzkwLWQxYWItNDkwNy05ZjVkLWIyZDhiZDM4MjdmMg
    

    与Serge insas的回答类似,这是我在使用UrlFetchApp.fetch时为了绕过401错误所必须做的

    var fileUrl = row[11] // Based on OP's case
    
    var attachment = [
       UrlFetchApp.fetch(fileUrl, {
          headers: { Authorization: 'Bearer ' + ScriptApp.getOAuthToken() },
       }).getBlob(),
    ]
    
    MailApp.sendEmail(emailAddress, subject, message, {attachments: attachment});
    
    https://drive.google.com/uc?export=view&id=0B3qSFd3iikE3TUFFLTc5MDE0MzkwLWQxYWItNDkwNy05ZjVkLWIyZDhiZDM4MjdmMg
    
    var fileUrl = row[11] // Based on OP's case
    
    var attachment = [
       UrlFetchApp.fetch(fileUrl, {
          headers: { Authorization: 'Bearer ' + ScriptApp.getOAuthToken() },
       }).getBlob(),
    ]
    
    MailApp.sendEmail(emailAddress, subject, message, {attachments: attachment});