LonamiWebs / Telethon

Pure Python 3 MTProto API Telegram client library, for bots too!
https://docs.telethon.dev
MIT License
10.01k stars 1.41k forks source link

Participant count over time #3919

Closed gerritq closed 2 years ago

gerritq commented 2 years ago

Hi,

first of all, I greatly enjoy using your library!

I was wondering whether you could give me an idea how to get participants counts form the past (to understand the growth of a channel).

According to issue #1648 which asked something similar, I tried the get_stats() method:

with TelegramClient(session, api_id, api_hash) as client:
    channel_stats = client.get_stats(channel=chat_name)
    # channel_request = client(GetFullChannelRequest(channel=channel_name)) 

However, I get the ChatAdminRequiredError exception altough the channel has about 150k participants (the documentation says this error may be raised when the group has not enough members):

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/code.py", line 90, in runcode
    exec(code, self.locals)
  File "<input>", line 5, in <module>
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/telethon/sync.py", line 39, in syncified
    return loop.run_until_complete(coro)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
    return future.result()
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/telethon/client/users.py", line 30, in __call__
    return await self._call(self._sender, request, ordered=ordered)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/telethon/client/users.py", line 84, in _call
    result = await future
telethon.errors.rpcerrorlist.ChatAdminRequiredError: Chat admin privileges are required to do that in the specified chat (for example, to send a message in a channel which is not yours), or invalid permissions used for the channel or group (caused by GetBroadcastStatsRequest)

I investigated the results from a GetFullChannelRequest of the same channel and I noticed that both attributes can_view_stats and can_view_participants are set to False.

Does this indicate that I am indeed not able to view stats? Is there a way to get a participant count history of a channel?

Many thanks in advance!

Lonami commented 2 years ago

I appreciate the kind words. However, Telethon is not producing that error. Telegram is, meaning there's likely nothing that can be done to fix it. I personally don't use that feature so I also don't know how, why or when it works. But your assumption is probably correct. I don't know how to get count history.

gerritq commented 2 years ago

Many thanks for quick response!!