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