如何通过TDLib从Telegram获取频道的数据列表?

huangapple go评论95阅读模式
英文:

how to get channel's data list from Telegram by TDLib?

问题

Telegram,我需要获取频道的数据列表。
我在这种情况下使用 TdApi。

文档:https://javadoc.tlgrm.ru/org/drinkless/td/libcore/telegram/TdApi.html
我基于这个示例进行操作:https://core.telegram.org/tdlib/tdlib.zip。

我仍然通过这个示例得到了聊天列表。请查看这里我的方法:

private suspend fun getChatIds(): LongArray {
    val getChats = TdApi.GetChats(TdApi.ChatListMain(), Long.MAX_VALUE, 0, 50)
    val chats = client.send<TdApi.Chats>(getChats)
    return chats.chatIds
}

suspend fun getChats(): List<TdApi.Chat> = getChatIds()
    .map { ids -> getChat(ids) }

suspend fun getChat(chatId: Long): TdApi.Chat {
    return client.send<TdApi.Chat>(TdApi.GetChat(chatId))
}

我尝试通过添加文档中的类进行修改。Channel,ChannelFull 以及 GetChannelFull。我将 GetChannelFull 添加到 Function 类中。在问题中,我通过 isChannel 过滤聊天,并尝试通过 supergroupId 获取频道。

suspend fun getChannels(): List<TdApi.ChannelFull> {
    return getChats().filter { chat -> chat.type is TdApi.ChatTypeSupergroup && (chat.type as TdApi.ChatTypeSupergroup).isChannel }
        .map { chat -> getChannel((chat.type as TdApi.ChatTypeSupergroup).supergroupId) }
}

但是,我得到了错误:检查 'request.function' 失败。

详情:
如何通过TDLib从Telegram获取频道的数据列表?

如果您知道问题出在哪里,请帮助我。

英文:

Telegram, I need to get channel's data list.
I use for this case TdApi.

Documentation: https://javadoc.tlgrm.ru/org/drinkless/td/libcore/telegram/TdApi.html
I do it based on this example: https://core.telegram.org/tdlib/tdlib.zip.

I still got chat's list by this example. Check here my way:

private suspend fun getChatIds(): LongArray {
        val getChats = TdApi.GetChats(TdApi.ChatListMain(), Long.MAX_VALUE, 0, 50)
        val chats = client.send&lt;TdApi.Chats&gt;(getChats)
        return chats.chatIds
    }

    suspend fun getChats(): List&lt;TdApi.Chat&gt; = getChatIds()
        .map { ids -&gt; getChat(ids) }

    suspend fun getChat(chatId: Long): TdApi.Chat {
        return client.send&lt;TdApi.Chat&gt;(TdApi.GetChat(chatId))
    }
enter code here

I tried to modificate this by adding classe from documentation. Channel, ChannelFull GetChannelFull. I added GetChannelFull into Function class. In the issue I filter chats by isChannel and try to get Channel by supergroupId.

suspend fun getChannels(): List&lt;TdApi.ChannelFull&gt; {
        return getChats().filter {chat -&gt;  chat.type is TdApi.ChatTypeSupergroup &amp;&amp; (chat.type as TdApi.ChatTypeSupergroup).isChannel }
            .map { chat -&gt; getChannel((chat.type as TdApi.ChatTypeSupergroup).supergroupId) }
    }

But, I get error: Check 'request.function' failed.

Details:
如何通过TDLib从Telegram获取频道的数据列表?

If you know what is that problem, please, help me.

答案1

得分: 1

我找到了一个解决方法。例如,有一个SupergroupFullInfo类,以及Chat类的ChatType。我将使用ChatType中的suprgroupId,并使用GetSupergroupFullInfo来获取所需信息。

英文:

I've found a resolve. In example there is SupergroupFullInfo class, and ChatType for Chat class. I will use suprgroupId from ChatType and GetSupergroupFullInfo for getting needed info.

huangapple
  • 本文由 发表于 2020年8月18日 17:13:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/63465464.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定