将电子表格图表的图像发送到Telegram时,发送的图像始终是相同的过时图像 [英] When sending image of a spreadsheet graph to Telegram, the image sent is always the same outdated
问题描述
我要发送给Telegram的图表的图像是这样的:
总是发送到电报的旧图像:
有什么方法可以强制更新发送到Telegram的图像吗?
解决方法:
- 从评论中的讨论中,我想提出以下解决方法.
- 幸运的是,当使用UrlFetchApp检索图像时,我可以在您的问题中看到上方的图像.我认为这可能可以使用.如果在当前阶段,您要使用的API无法检索具有相同URL的最新图像,作为一种解决方法,我想在Google云端硬盘上将最新图像创建为文件并发送该图像的URL.
- 从您的评论中,我还确认您已使用
https://drive.google.com/file/d/1zdEBhYircl9-P9Wtx-QyTgmxgskGLcEq/
作为photoUrl
.在这种情况下,无法正确显示图像文件.我认为需要修改端点.
当包含修改点的此解决方法是脚本时,它如下所示.
示例脚本1:
在此示例脚本中,从 https://docs.google.com/spreadsheets/d/e/2PACX-###/pubchart?oid=###&format=图片
,然后将图片创建为文件,然后通过修改图片大小来检索缩略图链接.
在使用此脚本之前,请请在高级Google上启用Drive API服务.
const url ="https://docs.google.com/spreadsheets/d/e/2PACX-1vRYIAQWrNu1P9fc0CzBXkMb2jsOCKhrRMoakqeq73BVWHNa6ukJHHK00ZvfNi5QQB2Pr7ACdw3yCBwV/479"?const res = UrlFetchApp.fetch(url);const文件= DriveApp.createFile(res.getBlob());const outputUrl = Drive.Files.get(file.getId()).thumbnailLink.replace("= s220","= s1000");console.log(outputUrl)//您可以在日志中看到链接.
示例脚本2:
在此示例脚本中,从 https://docs.google.com/spreadsheets/d/e/2PACX-###/pubchart?oid=###&format=图像
,然后将图像创建为文件,然后将文件公开共享并检索 webContentLink
.
const url ="https://docs.google.com/spreadsheets/d/e/2PACX-1vRYIAQWrNu1P9fc0CzBXkMb2jsOCKhrRMoakqeq73BVWHNa6ukJHHK00ZvfNi5QQB2Pr7ACdw3yCBwV/479"?const res = UrlFetchApp.fetch(url);const文件= DriveApp.createFile(res.getBlob());file.setSharing(DriveApp.Access.ANYONE_WITH_LINK,DriveApp.Permission.VIEW);const outputUrl =" https://drive.google.com/uc?export = download& id ="+ file.getId();console.log(outputUrl)//您可以在日志中看到链接.
- 在这种情况下,文件需要公开共享.请注意这一点.
参考文献:
The image of the graph I'm trying to send to Telegram is this:
The formula I use for shipping is this:
function EnviarTelegram(botSecret, chatId, photoUrl, caption) {
var response = UrlFetchApp.fetch("https://api.telegram.org/bot" + botSecret + "/sendPhoto?caption=" + encodeURIComponent(caption) + "&photo=" + encodeURIComponent(photoUrl) + "&chat_id=" + chatId + "&parse_mode=HTML");
}
But when I add the graphic link, it does not send the updated version, it always sends the first version of the image when I first published the image.
The formula I use looks like this:
=ENVIARTELEGRAM(W1,W2,"https://docs.google.com/spreadsheets/d/e/2PACX-1vRYIAQWrNu1P9fc0CzBXkMb2jsOCKhrRMoakqeq73BVWHNa6ukJHHK00ZvfNi5QQB2Pr7ACdw3yCBwV/pubchart?oid=1479223143&format=image",W19)
The correct image:
The old image that is always sent to Telegram:
Is there any way to force the update of this image that is sent to Telegram?
Workaround:
- From the discussions in the comment, I would like to propose the following workaround.
- Fortunately, when the image is retrieved using UrlFetchApp, I can see the upper image in your question. I thought that this might be able to be used. If in the current stage, the API you want to use cannot retrieve the latest image with the same URL, as a workaround, I would like to create the latest image as a file on Google Drive and send the URL of the image.
- From your comments, also I confirmed that you had used
https://drive.google.com/file/d/1zdEBhYircl9-P9Wtx-QyTgmxgskGLcEq/
as the value ofphotoUrl
. In this case, the image file cannot be correctly shown. I think that the endpoint is required to be modified.
When this workaround including the modification point is a script, it becomes as follows.
Sample script 1:
In this sample script, the chart image is retrieved from https://docs.google.com/spreadsheets/d/e/2PACX-###/pubchart?oid=###&format=image
and the image is created as a file, and then, the thumbnail link is retrieved by modifying the image size.
Before you use this script, please enable Drive API at Advanced Google services.
const url = "https://docs.google.com/spreadsheets/d/e/2PACX-1vRYIAQWrNu1P9fc0CzBXkMb2jsOCKhrRMoakqeq73BVWHNa6ukJHHK00ZvfNi5QQB2Pr7ACdw3yCBwV/pubchart?oid=1479223143&format=image";
const res = UrlFetchApp.fetch(url);
const file = DriveApp.createFile(res.getBlob());
const outputUrl = Drive.Files.get(file.getId()).thumbnailLink.replace("=s220", "=s1000");
console.log(outputUrl) // You can see the link at the log.
Sample script 2:
In this sample script, the chart image is retrieved from https://docs.google.com/spreadsheets/d/e/2PACX-###/pubchart?oid=###&format=image
and the image is created as a file, and then, the file is publicly shared and the webContentLink
is retrieved.
const url = "https://docs.google.com/spreadsheets/d/e/2PACX-1vRYIAQWrNu1P9fc0CzBXkMb2jsOCKhrRMoakqeq73BVWHNa6ukJHHK00ZvfNi5QQB2Pr7ACdw3yCBwV/pubchart?oid=1479223143&format=image";
const res = UrlFetchApp.fetch(url);
const file = DriveApp.createFile(res.getBlob());
file.setSharing(DriveApp.Access.ANYONE_WITH_LINK, DriveApp.Permission.VIEW);
const outputUrl = "https://drive.google.com/uc?export=download&id=" + file.getId();
console.log(outputUrl) // You can see the link at the log.
- In this case, the file is required to be publicly shared. Please be careful this.
References:
这篇关于将电子表格图表的图像发送到Telegram时,发送的图像始终是相同的过时图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!