0

I have to get data from all members of a list of Telegram chats – groups and supergroups –, but, as Pyrogram documentation alerts, it is only possible to get a total of 10,000 ChatMember results in a single query. Pyrogram's iter_chat_members method is limited to it and does not provide an offset parameter or some kind of pagination handling. So I tried to get 200-sized chunks of data with its get_chat_members method, but after the 50th chunk, which corresponds to the 10,000th ChatMember object, it starts to give me empty results. The draft code I used for testing is as follows:

from pyrogram import Client

def get_chat_members(app, target, offset=0, step=200):
    total = app.get_chat_members_count(target)
    itrs = (total//step) + 1
    members_list = []
    itr = 1
    while itr <= itrs:
        members = app.get_chat_members(target, offset)
        members_list.append(members)
        offset += step
        itr += 1
    return members_list

app = Client("my_account")
with app:
    results = get_chat_members(app, "example_chat_entity")
    print(results)

I thought that despite any of these methods giving me the full chat members data, there should be a workaround, given that what Pyrogram's documentation says about this limit corresponds to a single query. I wonder, then, if there is a way to do more than one query, without flooding the API, and without losing the offset state. Am I missing something or is it impossible to do due to an API limitation?

vmussa
  • 71
  • 7

1 Answers1

2

This is a Server Limitation, not one of Pyrogram itself. The Server simply does not yield any more information after ~10k members. There is no way that a user would need to know detailed information about this many members anyway.

ColinShark
  • 1,047
  • 2
  • 10
  • 18
  • Thanks for answering. In fact, an average user doesn't need this kind of information. But there are many analytical possibilities when it comes to getting full chat members' data. It seems that Telegram API doesn't favor and is not made for this kind of studies though. – vmussa May 17 '21 at 15:19
  • While yes, there surely are analytical possibilities, this also opens up the gateway for spammers and scammers. If you need to build a database of which members where in a channel or large supergroup, you can just periodically fetch the Recent Actions with [`get_chat_event_log()`](https://docs.pyrogram.org/api/methods/get_chat_event_log) – ColinShark May 17 '21 at 19:36