我尝试按用户名将用户添加到我的频道。我正在使用python 3.6 telethon库和pythonanywhere服务器:
api_hash = 'b7**'
phone = '+7***'
client = TelegramClient('new_ses', api_id, api_hash)
client.connect()
client = TelegramClient('session_neworig', api_id, api_hash,)
client.connect()
from telethon.tl.functions.channels import InviteToChannelRequest
from telethon.tl.functions.contacts import ResolveUsernameRequest
from telethon.tl.types import InputPeerChannel ,InputPeerUser,InputUser
from telethon.tl.functions.channels import JoinChannelRequest
chann=client.get_entity('channelname') #its public channel
print(chann.id)
1161823752
print(chann.access_hash)
8062085565372622341
time.sleep(30)
chan=InputPeerChannel(chann.id, chann.access_hash)
user = client(ResolveUsernameRequest('Chai***'))
print(user.users[0].id)
193568760
print(user.users[0].access_hash)
-4514649540347033311
time.sleep(1*30)
user=InputUser(user.users[0].id,user.users[0].access_hash,)
client.invoke(InviteToChannelRequest(chan,[user]))
这个剂量工作,我得到-telethon.errors.rpc_error_list.PeerFloodError: (PeerFloodError(...), 'Too many requests')
from telethon.helpers import get_input_peer
client.invoke(InviteToChannelRequest(
get_input_peer(client.get_entity(chan),
[get_input_peer(client.get_entity(user))]
))
请帮助,如何在没有任何禁令的情况下通过用户名添加200个用户,也许有另一种方法可以通过python执行此操作?另一个lib或api?
答案 0 :(得分:0)
from telethon.sync import TelegramClient
from telethon.tl.functions.channels import InviteToChannelRequest
from telethon.tl.types import InputPeerChannel ,InputUser
from telethon.tl.functions.contacts import ResolveUsernameRequest
api_id = ******
api_hash = '******'
phone = '+2519******'
client = TelegramClient(phone, api_id, api_hash);
client.connect()
chann=client.get_entity('channelname')
channel_id = chann.id;
channel_access_hash = chann.access_hash
chanal=InputPeerChannel(channel_id, channel_access_hash)
user = client(ResolveUsernameRequest('mrmi6'))
user=InputUser(user.users[0].id,user.users[0].access_hash,)
client(InviteToChannelRequest(chanal,[user]))
print('action completted')
答案 1 :(得分:0)
在 Telegram API 文档网站上找到了一些东西
每个电话号码每天只能进行一定数量的登录(例如 5 次,但这可能会发生变化),之后 API 将在第二天返回 FLOOD 错误。这可能不足以测试客户端应用程序中用户授权流程的实现。