【发布时间】:2019-09-06 14:03:44
【问题描述】:
所以我尝试了很长时间,我找到了一些预制程序,但它们的成本是 100 美元。我尝试了多个应用程序和程序,例如 Telegram Auto 和 Telegram Kit,但它们的成本很高,而且我现在没有这么多钱。
我正在尝试用 Python 和 Telethon 来做(没有太多经验)
我已经在电报开发者工具上做了一个app,拿到了API Number和Hash,在网上找到了如下代码
from telethon.tl.functions.messages import GetDialogsRequest
from telethon.tl.types import InputPeerEmpty
import csv
api_id = My API ID
api_hash = 'MY API HASH'
phone = 'MY PHONE'
client = TelegramClient(phone, api_id, api_hash)
client.connect()
chats = []
last_date = None
chunk_size = 200
groups=[]
result = client(GetDialogsRequest(
offset_date=last_date,
offset_id=0,
offset_peer=InputPeerEmpty(),
limit=chunk_size,
hash = 0
))
chats.extend(result.chats)
for chat in chats:
try:
if chat.megagroup== True:
groups.append(chat)
except:
continue
print('Choose a group to scrape members from:')
i=0
for g in groups:
print(str(i) + '- ' + g.title)
i+=1
g_index = input("Enter a Number: ")
target_group=groups[int(g_index)]
print('Fetching Members...')
all_participants = []
all_participants = client.get_participants(target_group, aggressive=True)
print('Saving In file...')
with open("members.csv","w",encoding='UTF-8') as f:
writer = csv.writer(f,delimiter=",",lineterminator="\n")
writer.writerow(['username','user id', 'access hash','name','group', 'group id'])
for user in all_participants:
if user.username:
username= user.username
else:
username= ""
if user.first_name:
first_name= user.first_name
else:
first_name= ""
if user.last_name:
last_name= user.last_name
else:
last_name= ""
name= (first_name + ' ' + last_name).strip()
writer.writerow([username,user.id,user.access_hash,name,target_group.title, target_group.id])
print('Members scraped successfully.')
我输入了我的信息,并启动了程序,但我不断收到此错误。
Traceback(最近一次调用最后一次): 文件“c:\Users\User\Desktop\export.py”,第 23 行,在 哈希 = 0 文件“C:\Users\User\AppData\Local\Programs\Python\Python37-32\lib\site-packages\telethon\sync.py”,第 39 行,同步 返回 loop.run_until_complete(coro) 文件“C:\Users\User\AppData\Local\Programs\Python\Python37-32\lib\asyncio\base_events.py”,第 579 行,在 run_until_complete 返回future.result() 调用中的文件“C:\Users\User\AppData\Local\Programs\Python\Python37-32\lib\site-packages\telethon\client\users.py”,第 64 行 结果 = 等待未来 telethon.errors.rpcerrorlist.AuthKeyUnregisteredError:密钥未在系统中注册(由GetDialogsRequest引起)
我到处搜索修复或教程,但没有找到任何东西。我唯一的另一个选择就是来这里。
请帮忙。
问候,丹尼尔
【问题讨论】:
-
这被认为是垃圾邮件,并且违反了电报的 ToS。如果您这样做,您的帐户将被禁止。
标签: python bots telegram telethon