【发布时间】:2020-08-14 05:35:07
【问题描述】:
我在 Google App Script 中使用以下代码在 Telegram Group 中发送图像。 每当我运行此代码时,照片都会发送到群组,但出现以下错误:
异常:https://api.telegram.org 的请求失败,返回代码 400。截断的服务器响应:{"ok":false,"error_code":400,"description":"错误请求:请求中没有照片"} (使用 muteHttpExceptions 选项检查完整响应)。 (第 27 行,文件“发送图像”)
目前我正在使用谷歌驱动器图片链接。 我尝试了来自不同来源的图像,但同样的错误
var photo_url = "https://docs.google.com/uc?id=File_Id";
var id = "Chat_Id";
sendPhoto(id,photo_url)
function sendPhoto(id,photo_url) {
var API_TOKEN = "BOT_API_Code";
var payload = {
'method': 'sendPhoto',
'chat_id': String(id),
'photo': photo_url,
'caption': "My Caption"
}
var data = {
"method": "post",
"payload": payload
}
UrlFetchApp.fetch('https://api.telegram.org/bot' + API_TOKEN + '/', data);
}
【问题讨论】:
-
如果您在浏览器中直接调用照片网址 URL,您会得到什么? (我认为这是 404 - 意味着确实没有照片)。尝试使用其他来源的照片 URL 来检查您的代码。
-
@jasie 实际上我使用的是 google drive 的照片 url
-
你没有回答我的问题。这么一来,我帮不上忙,对不起。
-
嗨@jasie,我确实尝试过来自其他来源的图片网址,但同样的错误,并且一直将图片发送到群组,但运行代码时显示错误。
标签: javascript google-apps-script google-sheets telegram-bot