[英]How to get all users in telegram chat with telebot or requests lib in Python?
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.
人们建议使用Telethon ,但我无法开始使用 Telethone 并想改用请求。 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.其中TOKEN是我的 bot 的 id, chat_id是聊天,我想从中获取列表。
req.content
returns me还我
b'{"ok":false,"error_code":404,"description":"Not Found"}'
https://core.telegram.org/method/channels.getFullChannel https://core.telegram.org/method/channels.getFullChannel
https://core.telegram.org/method/messages.getFullChat https://core.telegram.org/method/messages.getFullChat
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创建的会话将存储您需要手动添加的密码和/或电话号码
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.