google-apps-script - Photo sent by telegram bot from Google Drive is cropped
问题描述
I created a Telegram bot to send photos (currently in .jpg file type) to different commands. I'm using Google Apps Script because my photos are stored in my Google Drive and I thought it be a good idea to use a Sheet to keep track of my photos and their urls.
However, the photos that are being sent by the bot are cropped. I read through the API and didn't find anything specifying the dimensions of the photos needed. Could someone please shed light on this? How can I prevent Telegram from cropping my photos? Or, is that a preferred size that my photos should be so that it wouldn't be cropped?
More Information: I saved my photos in a google drive folder and manually created a sharing link and save them in my spreadsheet. Suppose I have a photo url in cell A1 of ActiveSpreadsheet, my code looks like this
photo_url = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getRange("A1").getValue();
sendPhoto(chatID,photo_url)
function sendPhoto(id,photo_url) {
var API_TOKEN = my_API_token;
var payload = {
'method': 'sendPhoto',
'chat_id': String(id),
'photo': photo_url,
}
var data = {
"method": "post",
"payload": payload
}
UrlFetchApp.fetch('https://api.telegram.org/bot' + API_TOKEN + '/', data);
}
解决方案
您需要注意photo_url
.
您可能正在使用该getUrl()
方法生成的 url:
https://drive.google.com/file/d/GOOGLE_DRIVE_FILE_ID
这将发送裁剪的图像。
另一方面,使用以下 url 将发送未截断的图像:
https://docs.google.com/uc?id=GOOGLE_DRIVE_FILE_ID
推荐阅读
- android - 为实现抽象值强制执行资源注释
- r - 多个变量的条形图
- android - 在 Android Studio 中更改 Google App Script 代码时是否需要更新 Play Store 应用程序?
- bash - v 开关在 bash 函数中不起作用(-v 开关)
- python - Tensorflow:model.fit() 第一个 epoch 需要很长的初始化时间
- xamarin - 使用 aries-mobileagent-xamarin / aries-framework-dotnet 创建凭据请求时出错
- java - Spring Security 错误:没有名为“springSecurityFilterChain”的 bean
- javascript - 如何使用 ES6 为隐藏的输入字段添加值
- version-control - 当没有任何更改时,Mercurial 合并失败并出现“未提交的更改”
- java - java.lang.IncompatibleClassChangeError:Primitives 没有实现请求的接口 org.apache.beam.vendor.grpc.v1p21p0.com.google.protobuf