我正在尝试使用 Python3 从 CSV 文件中导入联系人。
代码运行良好,没有显示任何错误,但联系人没有添加到 Telegram 中。任何想法为什么?
请看下面的代码:
import csv
from telethon import TelegramClient
from telethon.tl.functions.contacts import GetContactsRequest
from telethon.tl.types import InputPeerUser
from telethon.tl.types import InputPhoneContact
api_id = *******
api_hash = '*********'
client = TelegramClient('myname', api_id, api_hash)
client.connect()
with open('list.csv', 'r') as csv_file:
csv_reader = csv.reader(csv_file)
for line in csv_reader:
contact = InputPhoneContact(client_id = 0, phone = (line[0]), first_name=(line[1]), last_name=(line[2]))
contacts = client(GetContactsRequest(0))
result = client.invoke(ImportContactsRequest([contact]))