searchUsers
(Java / Swift / Objective-C / C++) interface to search for user information in the cloud,This interface returns user information stored in the cloud, including friend and non-friend information. You can call the checkFriend
(Java / Swift / Objective-C / C++) V2TIMUserSearchParam
are as follows:Parameter | Meaning | Description |
keywordList | Keyword list | It can contain up to five keywords,keyword will automatically match the user ID and nickname. |
keywordListMatchType | Match type of the keyword list | You can set it to search with "OR" logic or "AND" logic. The values are V2TIM_KEYWORD_LIST_MATCH_TYPE_OR and V2TIM_KEYWORD_LIST_MATCH_TYPE_AND , respectively. By default, it uses "OR" logic. |
gender | User gender | If not set, both male and female are returned by default. |
minBirthday | User’s minimum birthday | If not set, the default value is 0. |
maxBirthday | User's maximum birthday | If not set, all users with birthday >= minBirthday will be returned by default. |
searchCount | Search Count | Must be greater than 0, maximum supported is 100, default is 20. |
searchCursor | Search Cursor | Starting position, fill in an empty character string for the first time, and fill in the searchCursor from the last V2TIMUserSearchResult returned for subsequent pulls. |
V2TIMUserSearchResult
(Java / Swift / Objective-C / C++). The parameters are as described below:Parameter | Meaning | Description |
isFinished | Is the search finished | Whether all users that meet the search criteria have been returned. |
totalCount | Total search results | The total count of users that meet the search criteria. |
nextCursor | Continue pulling the cursor | The search cursor for the next cloud search. |
userList | User List | The user list returned by the current cloud search. |
V2TIMUserSearchParam searchParam = new V2TIMUserSearchParam();searchParam.setKeywordList(keywordList);searchParam.setKeywordListMatchType(param.V2TIM_KEYWORD_LIST_MATCH_TYPE_OR);searchParam.setSearchCount(20);searchParam.setSearchCursor("");V2TIMManager.getInstance().searchUsers(searchParam, new V2TIMValueCallback<V2TIMUserSearchResult>() {@Overridepublic void onSuccess(V2TIMUserSearchResult userSearchResult) {// search users succ}@Overridepublic void onError(int code, String desc) {// search users failed}});
let param = V2TIMUserSearchParam()param.gender = .V2TIM_GENDER_UNKNOWN;param.keywordList = ["keyword1", "keyword2"];param.keywordListMatchType = .V2TIM_KEYWORD_LIST_MATCH_TYPE_OR;param.searchCount = 20;param.searchCursor = "";V2TIMManager.shared.searchUsers(param: param) { searchResult in// search users succ} fail: { code, desc in// search users failed}
V2TIMUserSearchParam *param = [[V2TIMUserSearchParam alloc] init];param.gender = V2TIM_GENDER_UNKNOWN;param.keywordList = @[@"keyword1", @"keyword2"];param.keywordListMatchType = V2TIM_KEYWORD_LIST_MATCH_TYPE_OR;param.searchCount = 20;param.searchCursor = @"";[[V2TIMManager sharedInstance] searchUsers:param succ:^(V2TIMUserSearchResult *searchResult) {// search users succ} fail:^(int code, NSString *desc) {// search users failed}];
template <class T>class ValueCallback final : public V2TIMValueCallback<T> {public:using SuccessCallback = std::function<void(const T&)>;using ErrorCallback = std::function<void(int, const V2TIMString&)>;ValueCallback() = default;~ValueCallback() override = default;void SetCallback(SuccessCallback success_callback, ErrorCallback error_callback) {success_callback_ = std::move(success_callback);error_callback_ = std::move(error_callback);}void OnSuccess(const T& value) override {if (success_callback_) {success_callback_(value);}}void OnError(int error_code, const V2TIMString& error_message) override {if (error_callback_) {error_callback_(error_code, error_message);}}private:SuccessCallback success_callback_;ErrorCallback error_callback_;};V2TIMUserSearchParam searchParam;searchParam.keywordList = keywordList;param.keywordListMatchType = V2TIM_KEYWORD_LIST_MATCH_TYPE_OR;param.searchCount = 20;param.searchCursor = "";auto callback = new ValueCallback<V2TIMUserSearchResult>{};callback->SetCallback([=](const V2TIMUserSearchResult& userSearchResult) {// search users succdelete callback;},[=](int error_code, const V2TIMString& error_message) {// search users faileddelete callback;});V2TIMManager::GetInstance()->SearchUsers(searchParam, callback);
Was this page helpful?