Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/317.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何使用telethon获得电报专用信道中的所有用户?_Python_Telegram_Telethon - Fatal编程技术网

Python 如何使用telethon获得电报专用信道中的所有用户?

Python 如何使用telethon获得电报专用信道中的所有用户?,python,telegram,telethon,Python,Telegram,Telethon,我正在试图获得一份使用telethon的用户名单,该用户名单位于我作为管理员的私人电报频道,并将其打印到控制台。我用一个非私有的频道尝试了相同的代码,我也遇到了同样的问题 我想使用的用户名引用是什么?我不明白这是不是我的电报用户名,我的频道名称,我的电话号码,好像我要在频道里讲话,还是什么。有人能帮忙吗 from telethon import TelegramClient from telethon.tl.functions.contacts import ResolveUsern

我正在试图获得一份使用telethon的用户名单,该用户名单位于我作为管理员的私人电报频道,并将其打印到控制台。我用一个非私有的频道尝试了相同的代码,我也遇到了同样的问题

我想使用的用户名引用是什么?我不明白这是不是我的电报用户名,我的频道名称,我的电话号码,好像我要在频道里讲话,还是什么。有人能帮忙吗

  from telethon import TelegramClient

   from telethon.tl.functions.contacts import ResolveUsernameRequest
   from telethon.tl.functions.channels import GetAdminLogRequest
   from telethon.tl.functions.channels import GetParticipantsRequest

   from telethon.tl.types import ChannelParticipantsRecent
   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 = XXXX# Use your own values here. https://my.telegram.org
   api_hash = 'XXX'
   phone_number = 'XXXX'

   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('Jimtest')) # Your channel username --is this the username of my channel? how do I get the right value for this?   It isays username, but seems to reference the channel name?

user = client(ResolveUsernameRequest('@jim')) # what is this value? my username? my "name" in the chat?  the username that outputs when I type as admin in the chat?
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
filter = ChannelAdminLogEventsFilter(True, False, False, False, True, True, True, True, True, True, True, True, True, True)
cont = 0
list = [0,100,200,300]
for num in list:
 result = client(GetParticipantsRequest(InputChannel(channel.chats[0].id, channel.chats[0].access_hash), filter, num, 100, 0))
 for _user in result.users:
  print(_user.id)
我得到了以下错误,这些错误看起来与频道或用户名有关?这些值应该是什么

Traceback (most recent call last):
 File "./maybework.py", line 33, in <module>
    user = client(ResolveUsernameRequest('Jimtest')) # Your channel admin 
username
  File "/usr/local/lib/python3.6/dist- 
   packages/telethon/telegram_bare_client.py", line 459, in __call__
    result = self._invoke(call_receive, *requests)
  File "/usr/local/lib/python3.6/dist- 
   packages/telethon/telegram_bare_client.py", line 551, in _invoke
    raise next(x.rpc_error for x in requests if x.rpc_error)
telethon.errors.rpc_error_list.UsernameNotOccupiedError: The username is not in use by anyone else yet
回溯(最近一次呼叫最后一次):
文件“/maybework.py”,第33行,在
user=client(ResolveUsernameRequest('Jimtest'))#您的频道管理员
用户名
文件“/usr/local/lib/python3.6/dist-
包裹/电话电报/电报,客户机.py“,第459行,来电__
结果=自我调用(调用接收,*请求)
文件“/usr/local/lib/python3.6/dist-
packages/telethon/telegram\u bare\u client.py”,第551行,输入
引发下一个(如果x.rpc_错误,则请求中的x出现x.rpc_错误)
telethon.errors.rpc_error_list.UsernameNotOccupiedError:该用户名尚未被其他任何人使用
一旦我修复了那个错误,或者至少没有返回任何错误,我在下一次收到这个错误

Traceback (most recent call last):
  File "./maybework.py", line 33, in <module>
     user = client(ResolveUsernameRequest('jimtest')) # Your channel admin 
 username
   File "/usr/local/lib/python3.6/dist- 
packages/telethon/telegram_bare_client.py", line 459, in __call__
     result = self._invoke(call_receive, *requests)
   File "/usr/local/lib/python3.6/dist- 
 packages/telethon/telegram_bare_client.py", line 551, in _invoke
      raise next(x.rpc_error for x in requests if x.rpc_error)
 telethon.errors.rpc_error_list.UsernameNotOccupiedError: The username is not in use by anyone else yet
回溯(最近一次呼叫最后一次):
文件“/maybework.py”,第33行,在
user=client(ResolveUsernameRequest('jimtest'))#您的频道管理员
用户名
文件“/usr/local/lib/python3.6/dist-
包裹/电话电报/电报,客户机.py“,第459行,来电__
结果=自我调用(调用接收,*请求)
文件“/usr/local/lib/python3.6/dist-
packages/telethon/telegram\u bare\u client.py”,第551行,输入
引发下一个(如果x.rpc_错误,则请求中的x出现x.rpc_错误)
telethon.errors.rpc_error_list.UsernameNotOccupiedError:该用户名尚未被其他任何人使用

您可以在Telethon V 0.19中使用此代码

from telethon import TelegramClient
import socks

from telethon.tl.functions.channels import GetParticipantsRequest

api_id = XXXX
api_hash = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
phone_number = '+98XXXXXXXX'

################################################
# invite link for private channel
inveite_link='telegram.me/joinchat/AAAAAE84o7DErer_YqAohQ'
################################################
proxy_ip = 'YY.YY.YY.YY'
proxy_username = 'proxy_username'
proxy_password = 'proxy_password'
proxy_port = 123456
################################################

client = TelegramClient('session_name',
                    api_id,
                    api_hash,
                    proxy=(socks.HTTP, proxy_ip, int(proxy_port), 
None, proxy_username, proxy_password))

assert client.connect()
if not client.is_user_authorized():
    client.send_code_request(phone_number)
    me = client.sign_in(phone_number, input('Enter code: '))



channel = client.get_entity(inveite_link)

offset = 0
limit = 100

while True:
    participants = client(GetParticipantsRequest(
        channel, channel, offset, limit,hash=0))
    if not participants.users:
        break
    for _user in participants.users:
        print('user : ', _user.id, _user.username)
        # save User info to Database
    offset += len(participants.users)
  • 我用袜子。如果你不想穿袜子,就把它脱下来

  • 因为私人频道没有用户名,所以我使用了
    invite链接

  • 您也可以使用‍‍<代码>频道ID而不是
    邀请链接
    。在这种情况下,您应该使用
    channel=client.get\u实体(PeerChannel(channel\u id))
    而不是‍‍<代码>频道=客户端。获取实体(inveite链接)


您使用哪个版本?我很抱歉,使用上述代码只能获得200个用户,我如何才能获得更多用户?多达30000个用户