Telegram 电报API:我如何从一个我不是参与者的公共频道获取消息?

Telegram 电报API:我如何从一个我不是参与者的公共频道获取消息?,telegram,Telegram,一旦我知道它们的消息ID,我就能够通过请求从频道成功检索消息。顺便说一下,我找到了频道id 目前,mesage id是consequentive整数,因此获取max_id可以解决这个问题 我相信这是可能的,因为官方客户会这样做(查看频道而不加入)。我将通过阅读了解官方桌面应用程序是如何做到这一点的,但任何帮助都将不胜感激 我需要这个,因为我正在编写一个简单的公共电报频道->rss/web界面 请不要将电报客户端API与电报机器人API混淆。Bot API允许在新消息上接收“推送”消息,但不允许“

一旦我知道它们的
消息ID
,我就能够通过请求从频道成功检索消息。顺便说一下,我找到了频道id

目前,mesage id是consequentive整数,因此获取max_id可以解决这个问题

我相信这是可能的,因为官方客户会这样做(查看频道而不加入)。我将通过阅读了解官方桌面应用程序是如何做到这一点的,但任何帮助都将不胜感激

我需要这个,因为我正在编写一个简单的公共电报频道->rss/web界面


请不要将电报客户端API与电报机器人API混淆。Bot API允许在新消息上接收“推送”消息,但不允许“读取历史日志”。

结果是消息。getHistory还可以,为您提供最后N条消息+总计数

要从未加入的频道获取消息,您必须执行以下步骤:

  • 将用户名解析为ID并使用
    联系人访问\u散列。resolveUsername
  • 调用
    messages.getHistory
    以获取所需的消息
  • 以下是有关
    消息的简短说明。getHistory
    参数:

        :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)
    

    如何使用channels.getMessages?它必须像
    https://api.telegram.org/bot/channels.getMessages