代码之家  ›  专栏  ›  技术社区  ›  Ali Akhtari

在python中添加与telethon的联系

  •  0
  • Ali Akhtari  · 技术社区  · 7 年前

    1) Add new contact in api telegram python telethon ,我使用了以下代码:

    contact = InputPhoneContact(client_id=0, phone='+989122725691', first_name="user",
                            last_name="test")
    result = ImportContactsRequest(contacts=[contact])
    print(result)
    

    但我在我的输出中得到:

    ImportContactsRequest(contacts=[InputPhoneContact(client_id=0, phone='+989122725691', first_name='user', last_name='test')])
    

    1 回复  |  直到 7 年前
        1
  •  5
  •   Smart Manoj AlexP    7 年前

    您应该使用客户端实例调用ImportContactsRequest。 例如

    import random
    contact = InputPhoneContact(client_id=random.randint(0,9999), phone='+98912******', 
        first_name="user",
        last_name="test")
    result = client(ImportContactsRequest(contacts=[contact]))
    print(result.__dict__)
    

    作者注

    Official applications use random numbers ,及 we have had issues with it in the past