【问题标题】:Telegram API: How do I get messages from a public channel, which I am not participant of?Telegram API:如何从我未参与的公共频道获取消息?
【发布时间】:2018-02-17 10:33:42
【问题描述】:

一旦我知道他们的message IDs,我就可以通过channels.getMessages 请求从频道成功检索消息。顺便说一句,我通过contacts.search 找到频道ID。

目前,消息 ID 是连续整数,因此获取 max_id 可以解决问题。

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

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

请不要将 Telegram Client API 与 Telegram Bot API 混淆。 Bot API 允许在新消息上接收“推送”消息,但不能“读取历史日志”。

【问题讨论】:

  • 你如何使用channels.getMessages?一定要像https://api.telegram.org/bot<token>/channels.getMessages吗?

标签: telegram


【解决方案1】:

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

  1. contacts.resolveUsername将用户名解析为ID和access_hash
  2. 调用 messages.getHistory 以获取您想要的消息。

这里是关于messages.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)

【讨论】:

    【解决方案2】:

    结果messages.getHistory 没问题,给你最后N 条消息+ 总数。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-04-04
      • 1970-01-01
      • 2017-12-25
      • 2022-07-17
      • 2018-03-08
      • 1970-01-01
      • 2021-04-03
      • 2017-07-29
      相关资源
      最近更新 更多