Поиск телеги по номеру телефона с помощью user_api, успех в случае если у таргета доступен поиск по номеру для всех (по умолчанию).
В скрипте нужно заменить значения в строке 10, 11 и 12 (и 61 соответственно). Присутствует редактор только для UA и RU номеров.
В скрипте нужно заменить значения в строке 10, 11 и 12 (и 61 соответственно). Присутствует редактор только для UA и RU номеров.
Python:
from telethon import TelegramClient, events, sync
from telethon.tl.types import InputPhoneContact
from telethon import functions
import phonenumbers
class TGSearch(object):
def __init__(self):
####### YOUR DATA ###############
self.api_id = 1234567
self.api_hash = '*'
self.my_phone = '*YOUR PHONE NUM*'
################################
self.client = TelegramClient(self.my_phone, self.api_id, self.api_hash)
self.client.connect()
def numVCheck(self, t_phone):
if t_phone[0] != '+':
if t_phone[0] == '0':
t_phone = '+38' + t_phone
if t_phone[0:3] == '380' or t_phone[0:3] == '375':
t_phone = '+' + t_phone
if t_phone[0] == '8' or t_phone[0] == '7' or t_phone[0] == '9':
t_phone = '+7' + t_phone[1:]
for match in phonenumbers.PhoneNumberMatcher(t_phone, "RU"):
t_phone = phonenumbers.format_number(match.number, phonenumbers.PhoneNumberFormat.E164)
return t_phone
def check(self, t_phone):
try:
contact = InputPhoneContact(client_id=0, phone=t_phone, first_name="", last_name="")
contacts = self.client(functions.contacts.ImportContactsRequest([contact]))
user_id = contacts.to_dict()['users'][0]['id']
print('user ID =', user_id)
dell = self.client(functions.contacts.DeleteContactsRequest(id=[user_id]))
except:
user_id = 'error'
return user_id
def run(self, t_phone):
t_phone = t_phone
t_phone = self.numVCheck(t_phone)
if not self.client.is_user_authorized():
self.client.send_code_request(self.my_phone)
self.client.sign_in(self.my_phone, input('Enter the code: '))
user_id = self.check(t_phone)
if user_id != 'error':
try:
full = self.client(functions.users.GetFullUserRequest(id=user_id))
if full.user.username != None:
print(f'Name: @{full.user.username}')
print(f'First_name: {full.user.first_name}')
except:
print('Ошибка получения данных')
else:
print('Данных нету')
if __name__ == '__main__':
target_phone = '*TARGET PHONE*'
print('#' * 30)
TGSearch().run(target_phone)
print('#' * 30)