简体   繁体   中英

get telegram user_id by phone number in TDlib

I need to get user_id by phone number in Telegram using tdlib, I have tried addContact and importContacts , supposedly, they don't work for this purpose, and there is an old answer that doesn't work anymore. so, how would you get someones's user_id by phone contact info?

Works on 5th of Jan 2021

auto contact = td_api::make_object<td_api::contact>();
contact->phone_number_ = "70000000000";
auto contacts = td_api::make_object<td_api::importContacts>();
contacts->contacts_.emplace_back(std::move(contact));

send_query(std::move(contacts),
  [](Object object) {
    if (object->get_id() == td_api::error::ID) {
      return;
    }
  auto imported_contancs = td::move_tl_object_as<td_api::importedContacts>(object);
  for (auto uid : imported_contancs->user_ids_) {
    std::cout << "uid: " << uid << std::endl;
  }
  });


Needless to say, you have to have updates in place, but for this you can use Client instance example published as a documentation part.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM