Javascript 在哪里存储用于电报机器人API的文件?

Javascript 在哪里存储用于电报机器人API的文件?,javascript,google-apps-script,telegram-bot,Javascript,Google Apps Script,Telegram Bot,提前谢谢你的帮助 如何使用多部分/表单数据将本地照片文件传输到google drive 我已将本地文件复制到google drive,获得了google drive文件链接,但以下代码行挂起,出现了与html相关的错误 var response = UrlFetchApp.fetch(vUrlTelegram + "/sendPhoto?chat_id=" + chat_id + "&photo=" + photoUrl ); 注: 我们已经从互

提前谢谢你的帮助

如何使用多部分/表单数据将本地照片文件传输到google drive

我已将本地文件复制到google drive,获得了google drive文件链接,但以下代码行挂起,出现了与html相关的错误

var response = UrlFetchApp.fetch(vUrlTelegram + "/sendPhoto?chat_id=" + chat_id + "&photo=" + photoUrl );
注: 我们已经从互联网上获得了一张示例照片的html字符串,下面的电报机器人google api javascript代码可以正常工作

function sendPhoto( chat_id, photoUrl ) {
var response = UrlFetchApp.fetch(vUrlTelegram + "/sendPhoto?chat_id=" + chat_id + "&photo=" + photoUrl );
console.log(response.getContentText());  
}

电报文件

要发送的照片。 将文件id作为字符串传递,以发送电报服务器上存在的照片(推荐), 将HTTP URL作为字符串传递给电报,以便从Internet获取照片,或 使用多部分/表单数据上载新照片。有关发送文件的更多信息»

  • 根据您的问题,当internet上的图像直接链接用于以下脚本时,您可以确认脚本是否有效

      function sendPhoto( chat_id, photoUrl ) {
        var response = UrlFetchApp.fetch(vUrlTelegram + "/sendPhoto?chat_id=" + chat_id + "&photo=" + photoUrl );
        console.log(response.getContentText());
      }
    
在这种情况下,当您想使用Google Drive上的图像文件来执行上述脚本时,下面的流程如何

流量:
  • 任何人的
    查看器的身份在Google Drive上公开共享图像文件
  • 将图像文件的
    webContentLink
    用作
    photoUrl
    • 在这种情况下,当使用图像文件的文件ID时,
      webContentLink
      如下所示

        https://drive.google.com/uc?export=download&id={fileId}
      
      var fileId = "###"; // Please set the file ID of the image file.
      var file = DriveApp.getFileById(fileId)
      
      file.setSharing(DriveApp.Access.ANYONE_WITH_LINK, DriveApp.Permission.VIEW);  // Image file is publicly shared.
      
      var photoUrl = "https://drive.google.com/uc?export=download&id=" + fileId;
      var response = UrlFetchApp.fetch(vUrlTelegram + "/sendPhoto?chat_id=" + chat_id + "&photo=" + photoUrl );
      console.log(response.getContentText());
      
      // Utilities.sleep(2000); // I'm not sure whether this is required for this situation.
      file.setSharing(DriveApp.Access.PRIVATE, DriveApp.Permission.NONE);  // Sharing image file is stopped.
      
  • 示例脚本: 例如,当公开共享图像文件并运行
    UrlFetchApp.fetch
    并停止共享图像文件时,脚本如下所示

      https://drive.google.com/uc?export=download&id={fileId}
    
    var fileId = "###"; // Please set the file ID of the image file.
    var file = DriveApp.getFileById(fileId)
    
    file.setSharing(DriveApp.Access.ANYONE_WITH_LINK, DriveApp.Permission.VIEW);  // Image file is publicly shared.
    
    var photoUrl = "https://drive.google.com/uc?export=download&id=" + fileId;
    var response = UrlFetchApp.fetch(vUrlTelegram + "/sendPhoto?chat_id=" + chat_id + "&photo=" + photoUrl );
    console.log(response.getContentText());
    
    // Utilities.sleep(2000); // I'm not sure whether this is required for this situation.
    file.setSharing(DriveApp.Access.PRIVATE, DriveApp.Permission.NONE);  // Sharing image file is stopped.
    
    参考资料:

    你能描述一下你得到的错误吗?a/function sendPhoto(chat_id,photoUrl){var response=UrlFetchApp.fetch(vUrlTelegram+”/sendPhoto?chat_id=“+chat_id+”&photo=“+photoUrl”);console.log(response.getContentText());}有效,因为我已经测试了照片html链接1.1/是这个链接有效1.2/否,此链接不存在work@Trajano罗伯托:谢谢你的回复。我不得不为我糟糕的英语水平道歉。很遗憾,我无法理解你的答复。我能问一下细节吗?我想确认一下。在我将google drive文件夹更改为:anywhere with the link”后,它现在可以工作了。查看者感谢您的回复。现在我可以理解了。我很高兴您的问题得到了解决。谢谢。