【问题标题】:go-tdlib how to use SearchContactsgo-tdlib 如何使用 SearchContacts
【发布时间】:2021-01-20 10:55:57
【问题描述】:

我想根据用户名搜索未知用户。

我正在使用来自this 库的SearchContacts 方法。根据方法签名,第一个参数应该是代表查询的string。不幸的是,我找不到任何关于如何格式化查询的文档。

您可以在下面找到我的代码 sn-p:

contacts, err := telegramClient.SearchContacts(fmt.Sprintf("username=%s", username), 1)

【问题讨论】:

  • 你试过只提供搜索字符串吗? SearchContacts(username, 1)
  • 是的,我有。 contacts 结构没有用户:&{tdCommon:{Type:users Extra:HnHNClFZNDaAGFQBZFpRcvMGyaLLJhdx} TotalCount:0 UserIDs:[]}

标签: go tdlib


【解决方案1】:

根据文档:

// SearchContacts Searches for the specified query in the first names, last names
// and usernames of the known user contacts
// @param query Query to search for; may be empty to return all contacts
// @param limit The maximum number of users to be returned
func (client *Client) SearchContacts(query string, limit int32) (*Users, error) {
    // ...
}

该功能似乎不搜索未知用户,而只搜索known user contacts

好像没有搜索未知用户的方法。

【讨论】:

  • 哦。是的你是对的。因此,通过用户名搜索用户的有效解决方案是使用方法SearchChatschats, err := telegramClient.SearchChats(username, 1) 在该切片之后 chats.ChatIDs 将包含所需用户的 id。
猜你喜欢
  • 1970-01-01
  • 2016-10-13
  • 1970-01-01
  • 1970-01-01
  • 2020-07-25
  • 2016-09-06
  • 2020-01-02
  • 2023-01-14
  • 1970-01-01
相关资源
最近更新 更多