Javascript 在哪里存储用于电报机器人API的文件?
提前谢谢你的帮助 如何使用多部分/表单数据将本地照片文件传输到google drive 我已将本地文件复制到google drive,获得了google drive文件链接,但以下代码行挂起,出现了与html相关的错误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 ); 注: 我们已经从互
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上公开共享图像文件
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.
参考资料: