首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何导出电报的会员名单?

如何导出电报的会员名单?
EN

Web Applications用户
提问于 2019-01-07 20:38:24
回答 2查看 19.2K关注 0票数 2

我想导出频道或组当前成员的列表。是否可以通过UI、替代客户端(如Bettergram)、电报API机器人API

我在一些营销应用程序(比如电报自动)上看到了这个特性,但我更喜欢自己来做。

其中一个用例是将成员从频道移到组 (不手动单击所有成员),所以这个问题假设我有管理权限,但是如果该方法对其他通道/组有效,那就更好了。

怎样才能做到这样的出口?

EN

回答 2

Web Applications用户

回答已采纳

发布于 2019-01-07 21:00:54

您可以尝试Telethon,它可以提取给定组的所有成员并将其保存在SQLite数据库中。当然,你需要成为频道的管理员。

您可以使用这样的方法获得它:

代码语言:javascript
运行
复制
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))

或者这样的方法:

代码语言:javascript
运行
复制
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/

资源:

票数 4
EN

Web Applications用户

发布于 2021-12-15 19:05:33

恢复一个老问题,但电报有自己的API为这一要求。

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

它们的示例代码如下:

代码语言:javascript
运行
复制
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;
票数 1
EN
页面原文内容由Web Applications提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://webapps.stackexchange.com/questions/123798

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档