发布于 2019-01-07 21:00:54
您可以尝试Telethon,它可以提取给定组的所有成员并将其保存在SQLite数据库中。当然,你需要成为频道的管理员。
您可以使用这样的方法获得它:
from telethon import TelegramClient
from telethon.tl.functions.contacts import ResolveUsernameRequest
from telethon.tl.functions.channels import GetAdminLogRequest
from telethon.tl.types import InputChannel
from telethon.tl.types import ChannelAdminLogEventsFilter
from telethon.tl.types import InputUserSelf
from telethon.tl.types import InputUser
# These example values won't work. You must get your own api_id and
# api_hash from https://my.telegram.org, under API Development.
api_id = ****** # Your api_id
api_hash = '********************************' # Your api_hash
phone_number = '+989122594574' # Your phone number
client = TelegramClient(phone_number, api_id, api_hash)
client.session.report_errors = False
client.connect()
if not client.is_user_authorized():
client.send_code_request(phone_number)
client.sign_in(phone_number, input('Enter the code: '))
channel = client(ResolveUsernameRequest('tabe_eshgh')) # Your channel username
user = client(ResolveUsernameRequest('amir2b')) # Your channel admin username
admins = [InputUserSelf(), InputUser(user.users[0].id, user.users[0].access_hash)] # admins
admins = [] # No need admins for join and leave and invite filters
filter = None # All events
# param: (join, leave, invite, ban, unban, kick, unkick, promote, demote, info,
# settings, pinned, edit, delete)
filter = ChannelAdminLogEventsFilter(True, True, True, False, False, False, False,
False, False, False, False, False, False, False)
result = client(GetAdminLogRequest(InputChannel(channel.chats[0].id,
channel.chats[0].access_hash), '', 0, 0, 10, filter, admins))
##print(result)
for _user in result.users:
##print(_user.id)
with open(''.join(['users/', str(_user.id)]), 'w') as f:
f.write(str(_user.id))
或者这样的方法:
from telethon import TelegramClient, sync
api_id = 'FILL REAL VALUES HERE'
api_hash = 'FILL REAL VALUES HERE'
client = TelegramClient('xxx', api_id, api_hash).start()
# get all the channels that I can access
channels = {d.entity.username: d.entity
for d in client.get_dialogs()
if d.is_channel}
# choose the one that I want to list users from
channel = channels[channel_name]
# get all the users and print them
for u in client.get_participants(channel):
print(u.id, u.first_name, u.last_name, u.username)
但是,首先,您需要通过使用现有的电报帐户登录到api_id和api_hash并获得凭据,从而使用MTProto获得MTProto和https://my.telegram.org/。
发布于 2021-12-15 19:05:33
恢复一个老问题,但电报有自己的API为这一要求。
https://core.telegram.org/method/channels.getParticipants
它们的示例代码如下:
channels.channelParticipants#9ab0feaf count:int participants:Vector<ChannelParticipant> chats:Vector<Chat> users:Vector<User> = channels.ChannelParticipants;
channels.channelParticipantsNotModified#f0173fe9 = channels.ChannelParticipants;
---functions---
channels.getParticipants#77ced9d0 channel:InputChannel filter:ChannelParticipantsFilter offset:int limit:int hash:long = channels.ChannelParticipants;
https://webapps.stackexchange.com/questions/123798
复制相似问题