So I've been trying for a long time, I found some pre-made programs, but they costs 100$. I've tried multiple apps and programs like Telegram Auto and Telegram Kit, but they cost a lot and I don't have such money right now.
I am trying to do it in Python and Telethon(Don't have a lot of experience in it)
I already made an app on telegram developer tools, got the API Number and Hash, and found the following code online
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.')
I entered My information, and I started the program, but I keep getting this error.
Traceback (most recent call last): File "c:\Users\User\Desktop\export.py", line 23, in hash = 0 File "C:\Users\User\AppData\Local\Programs\Python\Python37-32\lib\site-packages\telethon\sync.py", line 39, in syncified return loop.run_until_complete(coro) File "C:\Users\User\AppData\Local\Programs\Python\Python37-32\lib\asyncio\base_events.py", line 579, in run_until_complete return future.result() File "C:\Users\User\AppData\Local\Programs\Python\Python37-32\lib\site-packages\telethon\client\users.py", line 64, in call result = await future telethon.errors.rpcerrorlist.AuthKeyUnregisteredError: The key is not registered in the system (caused by GetDialogsRequest)
I searched everywhere for a fix or a tutorial and I didn't find anything. My only other choice was coming here.
Please Help.
Regards, Daniel