5

I try really hard to understand howto use Telegram api with telethon. I have some Channels in Telegram, where i want to delete older Messages. Using inputpeerchannel() i need channel_id (No Problem) and channel_hash. I cant findout howto get this channel_hash by channel_id. Thank you from germany

4

2 回答 2

9

为了找到频道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()
于 2017-10-14T05:39:32.667 回答
0

获取访问哈希的方法有 4 种:

  1. 从一个组
  2. 从用户名
  3. 从联系人列表
  4. 来自聊天消息

因此,如果您只有 id,则无法获取访问哈希

于 2020-04-30T09:00:47.227 回答