簡體   English   中英

如何讓所有用戶與 Telebot 進行電報聊天或在 Python 中請求 lib?

[英]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"}'

https://core.telegram.org/method/channels.getFullChannel

https://core.telegram.org/method/messages.getFullChat

我解決了我的問題,這是代碼

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM