I want to get list of all users in my channel/chat. People suggests using telethon , but i can't get started with telethone and want to use requests instead. Can u help me please?
I tried
import json
import requests
URL = "https://api.telegram.org/bot{}/".format(TOKEN)
url = URL + "getFullChat?chat_id={}".format(chat_id)
req = requests.get(url)
where TOKEN is my bot's id and chat_id is the chat, where I want to get the list from.
req.content
returns me
b'{"ok":false,"error_code":404,"description":"Not Found"}'
I solved my problem, here is the code
from telethon.sync import TelegramClient
api_id = XXX # int
api_hash = 'XXX'
client = TelegramClient('session_name_choose_yourself', api_id, api_hash)
assert client.start()
if not client.is_user_authorized():
client.send_code_request(bot_token)
entity=client.get_entity("@ChatUserName")
users = client.get_participants(entity)
print(len(users))
for i in users:
print(i.id, i.username, i.first_name, i.last_name)
The session created will store the password and/or telephone number you need to add manually
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.