Telegram bot - receive photo URL

吃可爱长大的小学妹 提交于 2019-12-21 22:31:07

问题


When a user send an image via Telegram bot it there any way to get the image URL? or I just need to save the image somewhere?


回答1:


In the message array you receive you can find the key photo. There you will find multiple arrays with the following format

"file_id" : "XXXX",
"file_size" : 1107,
"width" : 90,
"height" : 51

From one of those array you need to take the file_id. You can then request the file_path with a simple get get on the url https://api.telegram.org/bot<token>/getFile?file_id=<file_id>

You will receive an array that looks as following

"ok" : true,
"result" : {
    "file_id" : "XXXX",
    "file_size" : 27935,
    "file_path" : "photo\/file_1.jpg"
}

From the result you need the file_path and you then got the image location https://api.telegram.org/file/bot<token>/<file_path>



来源:https://stackoverflow.com/questions/35991698/telegram-bot-receive-photo-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!