Telegram API: How do I get messages from a public channel, which I am not participant of?

Here are the steps you have to do in order to get messages from a channel you're not joined:

  1. Resolve the username into ID and access_hash with contacts.resolveUsername
  2. Invoke messages.getHistory to get your desired messages.

Here is a short description on messages.getHistory parameters:

    :param peer:        The channel from whom to retrieve the message history
    :param limit:       Number of messages to be retrieved
    :param offset_date: Offset date (messages *previous* to this date will be retrieved)
    :param offset_id:   Offset message ID (only messages *previous* to the given ID will be retrieved)
    :param max_id:      All the messages with a higher (newer) ID or equal to this will be excluded
    :param min_id:      All the messages with a lower (older) ID or equal to this will be excluded
    :param add_offset:  Additional message offset (all of the specified offsets + this offset = older messages)

It turns out messages.getHistory is just okay, gives you last N messages + total count.

Tags:

Telegram