2017-10-13 166 views
3

我真的很难理解如何使用Telethon使用Telegram api。我在电报中有一些频道,我想删除旧的消息。使用inputpeerchannel()我需要channel_id(没有问题)和channel_hash。我无法找到如何通过channel_id获取此channel_hash。谢谢德国电报频道 - 如何获得access_hash?

+0

您是否找到解决方案? – flagg19

回答

1

为了找到频道access_hash,你应该解决频道用户名。原始MTPROTO方法contacts.resolveUsername#f93ccba3获取@username并返回频道信息,包括access_hash

在telethon中,您需要调用ResolveUsernameRequest来调用上述原始MTProto方法。您可以使用此代码将用户名解析为access_hash

client = TelegramClient(session_file, api_id=00000, api_hash='XXXXX') 
client.connect() 
response = client.invoke(ResolveUsernameRequest("your_channel_id")) 
print(response.chats[0].access_hash) 
client.disconnect() 
+0

“your_channel_id”是用户名还是channel_id?它不适合我与channel_id,它与用户名,但我只有channel_id – flagg19

+0

“your_channel_id”是一个字符串,它是用户名。您只能通过'channel_id'访问频道。你也需要'access_hash'。 –