如何让所有用户与 telebot 进行电报聊天或在 Python 中请求 lib?
How to get all users in telegram chat with telebot or requests lib in Python?
我想获得我 channel/chat 中所有用户的列表。人们建议使用 telethon,但我无法开始使用 telethone,而是想使用 requests。你能帮帮我吗?
我试过了
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 是我的机器人 ID,chat_id 是聊天,我想从中获取列表。
req.content
returns我
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)
创建的会话将存储密码and/or您需要手动添加的电话号码
我想获得我 channel/chat 中所有用户的列表。人们建议使用 telethon,但我无法开始使用 telethone,而是想使用 requests。你能帮帮我吗?
我试过了
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 是我的机器人 ID,chat_id 是聊天,我想从中获取列表。
req.content
returns我
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)
创建的会话将存储密码and/or您需要手动添加的电话号码