![](/img/trans.png)
[英]How to send a photo with compressing (in order to show in full size) in telegram using telethon
[英]is there any way to know the url of telegram post photo using telethon?
我使用python和telethon來獲取消息..我可以下載消息照片,但我不想存儲和下載。 我想知道照片的網址,以便以后隨時使用它訪問它。 有沒有辦法做到這一點?
電報API不會為您提供直接到帖子媒體文件的URL。 但是,作為一種解決方法,請看一下幾個月前Telegram在其網站上添加的新功能:
您只需輸入以下格式的網址即可查看網絡中公共頻道的帖子: https : //t.me/ “ channel-username” /“ post-No”
(例如https://t.me/gizmiztel/2350 )
這樣,您可以解析DOM並找到每個媒體文件的直接URL。
注意:對於每種類型的文件,您可能需要一種單獨的方法來提取文件的URL。
@tashakori 答案的擴展
對於沒有設置用戶名的頻道(我見過幾個),它是https://t.me/c/channel_id/message_id
例如。
async def main():
# TODO setup client etc.
# this channel id was obtained from using something similar to https://stackoverflow.com/a/62849271/8608146
channel = await client.get_entity(-1001006503122)
async for message in client.iter_messages(channel, reverse=True):
# channel.id and the above -100.. id are not same
# this channel.id looks like 1006503122
print("message URL", f"https://t.me/c/{channel.id}/{message.id}")
另請注意:當然,只有加入頻道的用戶才能訪問這些鏈接。
還有message.chat_id
屬性返回 -100 ...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.