S
S
Sergey Ilyin2021-10-05 23:51:34
Python
Sergey Ilyin, 2021-10-05 23:51:34

How to get the number of channel subscribers in Telegram?

Good afternoon. For the purpose of enriching the ML model, I would like to collect data on the number of channel subscribers in the telegram. I am not the owner of the channel, but I would like to get the number of subscribers. Tell me how this can be done?
i tried the method getChatMemberCountand got the view url

https://api.telegram.org/bot{api_id}:{api_hash}/[email protected]{url_channel}
.
However, such a request returns me a 401 error: HTTPError: HTTP Error 401: Unauthorized, apparently saying that I have nothing to do with this channel. Tell me, are there any options?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
soremix, 2021-10-06
@sunsexsurf

Either through a bot or through a client API.
Through the bot, you need to get the bot token from @BotFather and paste the token into your URL. Or use any convenient library:

import telebot

token = 'XXX'
channel = '@XYZ'

bot = telebot.TeleBot(token)
print(bot.get_chat_member_count(channel))

Through the client API and any convenient library.
Data can be taken at my.telegram.org
from telethon import TelegramClient, sync 
from telethon.tl.functions.channels import GetFullChannelRequest


api_id = ZZZ
api_hash = 'YYY'
channel_name = 'XXX'

client = TelegramClient('session_name', api_id, api_hash)
client.start()

channel_connect = client.get_entity(channel_name)
channel_full_info = client(GetFullChannelRequest(channel=channel_connect))
print(channel_full_info.full_chat.participants_count)

W
wz, 2021-10-05
@rensly

https://ru.stackoverflow.com/questions/783686/%D0%...

D
Demiarius, 2022-04-17
@Demiarius

This only works for me if there is an @invite channel name. And how to do the same for the channel id?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question