Showing posts with label telegram export channel members. Show all posts
Showing posts with label telegram export channel members. Show all posts

Friday, April 15, 2022

Telegram - Export Members of a Channel

There are two conditions to Import / Export members of a telegram channel.

1) You should be an administrator or owner of the channel, then only you will be able to import or export members.

2) If a member has selected ‘My Contacts’ option in ‘who can add you to groups and channels’ then you should be added in his/her contact list only then you can add him/her in the channel.

To export channel members, First Generate api id and api hash in your telegram account. To do this, open my.telegram.org
Login using your registered phone number.
Now Open Link Development Tools and copy your api id and hash
We will use the api id and hash in the Python Script

 Create virtual environment with python 3 and install Telethon using pip.

virtualenv telegram -p /usr/bin/python3
source telegram/bin/activate
pip install Telethon==1.23.0

Update API ID, API hash, telegram registered phone number and channel username(it can be found on the channel description page) whose members you want to export in the following python script export.py.

from telethon import TelegramClient, sync
from telethon.tl.functions.channels import GetParticipantsRequest
from telethon.tl.functions.channels import GetFullChannelRequest
from telethon.tl.types import ChannelParticipantsSearch

api_id = 9999999
api_hash = 'zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz'
phone_number = '+919999999999'
channel_username = 'rajcomicsoldads'

client = TelegramClient(phone_number, 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 list users from
channel = channels[channel_username]
#print(client.get_participants(channel))
# get all the users and print them
print('username',",",'user id',",",'access hash',",",'name',sep='')
for u in client.get_participants(channel):
    print(u.username,",",u.id,",",u.access_hash,",",u.first_name," ",u.last_name,sep='')

Run the Python script in the same virtual env.

python export.py

It will list all your channels. Choose number whose members you want to export.

It will list all members of the channel in the csv format. Copy this output in the file members.csv 

To see the steps :


 

Telegram Import Channel Members :

 https://linuxamination.blogspot.com/2022/03/telegram-import-members-of-channel.html