Search code examples
pythontelethontelegram-api

Telethon API - How to get channel info and messages with only channel ID and name?


I have a simple question about the Telethon API for a personal project of mine.

The project is as follows: I extracted various channel IDs and channel names from the published TGDataset, and I would like to see if these channels are still active. If so, I would like to retrieve latest information and messages of the channel. The problem is that I do not have the channels' access hashes available in the dataset. Assuming that these are public channels, is there a way that I can do this without knowing the access hash? If not, how should I proceed to get the corresponding access hash of a channel?

Thank you so much for your time and effort. I would greatly appreciate all the help and guidance you can provide.


Solution

  • The ID alone is not enough to fetch a channel (see What is access_hash in telegram API?), but the username is, and in v1, client.get_entity can be used to fetch "entities" given the username.

    Note that Telegram heavily restricts how often resolving usernames can be done, and you will quickly run into flood waits which cannot be avoided or worked around.