首页 > 解决方案 > 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);
}

标签: google-apps-scripttelegram-bot

解决方案


您需要注意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

推荐阅读