我应该将什么作为偏移量和限制参数传递给电报核心 api 中的 getFile 方法?
what should i pass as offset and limit parameters to getFile method in telegram core api?
我想通过调用 getFile
方法下载图片文件,这是我使用 telethon(电报客户端 api)的代码:
def get_file_req(client, volume_id, local_id, secret):
input_file_location = InputFileLocation(volume_id, local_id, secret)
downloaded_file = client(GetFileRequest(input_file_location, 4000, 2000))
return downloaded_file
print(get_file_req(client, 434327164, 120080, 1200912808185991895))
我不知道应该将哪些参数传递给 GetFileRequest
方法。基于 this link,GetFileRequest
给出 location
,offset
和 limit
作为参数,并提到偏移量必须能被 1KB 整除,但没有一个很好的例子来说明我应该将哪些参数传递给此方法。当我调用此方法时出现此错误:
Traceback (most recent call last):
File "tclient.py", line 27, in <module>
print(get_file_req(client, 434327164, 120080, 1200912808185991895))
File "tclient.py", line 23, in get_file_req
downloaded_file = client(GetFileRequest(input_file_location, 4000, 2000))
File "C:\Users\Ali\Desktop\projects\telegram bot dev branch\myenv\Lib\site-packages\telethon\telegram_bare_client.py", line 429, in __call__
sender, call_receive, update_state, *requests
File "C:\Users\Ali\Desktop\projects\telegram bot dev branch\myenv\Lib\site-packages\telethon\telegram_bare_client.py", line 517, in _invoke
raise next(x.rpc_error for x in requests if x.rpc_error)
telethon.errors.rpc_error_list.OffsetInvalidError: (OffsetInvalidError(...), 'The given offset was invalid, it must be divisible by 1KB. See https://core.telegram.org/api/files#downloading-files')
我认为使用 telethon
下载文件的最佳示例是 telegram_bare_client.py
。看看吧here.
这是您应该感兴趣的方法:
def download_file(self,
input_location,
file,
part_size_kb=None,
file_size=None,
progress_callback=None):
向下滚动或搜索并找到它。这个函数比较大,调用了很多其他的自定义函数,这里就不复制了。
我想通过调用 getFile
方法下载图片文件,这是我使用 telethon(电报客户端 api)的代码:
def get_file_req(client, volume_id, local_id, secret):
input_file_location = InputFileLocation(volume_id, local_id, secret)
downloaded_file = client(GetFileRequest(input_file_location, 4000, 2000))
return downloaded_file
print(get_file_req(client, 434327164, 120080, 1200912808185991895))
我不知道应该将哪些参数传递给 GetFileRequest
方法。基于 this link,GetFileRequest
给出 location
,offset
和 limit
作为参数,并提到偏移量必须能被 1KB 整除,但没有一个很好的例子来说明我应该将哪些参数传递给此方法。当我调用此方法时出现此错误:
Traceback (most recent call last):
File "tclient.py", line 27, in <module>
print(get_file_req(client, 434327164, 120080, 1200912808185991895))
File "tclient.py", line 23, in get_file_req
downloaded_file = client(GetFileRequest(input_file_location, 4000, 2000))
File "C:\Users\Ali\Desktop\projects\telegram bot dev branch\myenv\Lib\site-packages\telethon\telegram_bare_client.py", line 429, in __call__
sender, call_receive, update_state, *requests
File "C:\Users\Ali\Desktop\projects\telegram bot dev branch\myenv\Lib\site-packages\telethon\telegram_bare_client.py", line 517, in _invoke
raise next(x.rpc_error for x in requests if x.rpc_error)
telethon.errors.rpc_error_list.OffsetInvalidError: (OffsetInvalidError(...), 'The given offset was invalid, it must be divisible by 1KB. See https://core.telegram.org/api/files#downloading-files')
我认为使用 telethon
下载文件的最佳示例是 telegram_bare_client.py
。看看吧here.
这是您应该感兴趣的方法:
def download_file(self,
input_location,
file,
part_size_kb=None,
file_size=None,
progress_callback=None):
向下滚动或搜索并找到它。这个函数比较大,调用了很多其他的自定义函数,这里就不复制了。