我如何获得电报机器人的 file_path [英] How can i get file_path of telegram bot

查看:29
本文介绍了我如何获得电报机器人的 file_path的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个像

{  
   "update_id":236420475,
   "message":{  
      "message_id":26577,
      "from":{  
         "id":xxxxxxxx,
         "first_name":"DB",
         "last_name":"Ks",
         "username":"xxxxxxxx"
      },
      "chat":{  
         "id":193044649,
         "first_name":"DB",
         "last_name":"Ks",
         "username":"xxxxxxxx",
         "type":"private"
      },
      "date":1493266832,
      "voice":{  
         "duration":2,
         "mime_type":"audio/ogg",
         "file_id":"AwADBQADBAADQKMIVC978KStO6ZhAg",
         "file_size":7532
      }
   }
} 

telegram bot API 文档 中有一个 file_path 指定用于下载文件.如何使用 file_id 获取 file_path 或用于获取 file_path 的任何 API?

From the telegram bot API documentation there is a file_path specified for downloading the file. How can i get the file_path or any API for getting file_path by using file_id?

推荐答案

您可以分两步下载文件:

You can download a file in 2 steps:

  1. 调用 getFile() ,作为响应,您将得到一个响应,如 Alexey Shablowski 所示,其中 file_path 与响应值
  2. 使用此文件路径调用其文件下载端点.
  1. call getFile() , in response you will be given a response as Alexey Shablowski has shown above where a file_path is returned with the response value
  2. use this file path to call their file-downloading endpoint.

例如.假设您的机器人 auth 令牌:1234:abcdfile_id:'xyz890'

getFile 请求:

Ex. let's say, your bot auth token: 1234:abcd and file_id: 'xyz890'

getFile request:

https://api.telegram.org/bot1234:abcd/getFile?file_id=xyz890

回复:

   {
      "ok": true,
      "result": 
        {
           "file_id": "xyz890",
           "file_size": 911,
           "file_path": "photos/file_name.jpg" 
         }
    }

现在获取 file_path 字符串值并构建完整的可下载链接:

Now get the file_path string value and construct your full downloadable link:

https://api.telegram.org/file/bot1234:abcd/photos/file_name.jpg


API 详细信息

这篇关于我如何获得电报机器人的 file_path的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆