tencent cloud

14天试用边缘安全加速平台 EO 限时免费

Feedback

Chat

Android&iOS&Windows&Mac

Last updated: 2025-01-23 15:39:03

Search Cloud Users

Description

You can search for cloud users by user ID, nickname, gender, and other information to quickly find the required user profile. This feature is suitable for scenarios where specific user information needs to be found, such as finding users to add as friends in familiar social scenes or finding users to follow in stranger social scenes.
Note:
The cloud user search feature is supported only by version 8.4 or later.
This feature is a value-added feature, see Billing Overview for more information.
If this service is not activated, calling the interface will return the error code 60020.

Search Cloud Users Interface

Call the 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++)
interface to determine whether a user is a friend.
The parameters of 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.

User Search Result Class

The message search result class is V2TIMUserSearchResultJava / 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.
Below is the sample code:
Java
Swift
Objective-C
C++
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>() {
@Override
public void onSuccess(V2TIMUserSearchResult userSearchResult) {
// search users succ
}

@Override
public 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 succ
delete callback;
},
[=](int error_code, const V2TIMString& error_message) {
// search users failed
delete callback;
});

V2TIMManager::GetInstance()->SearchUsers(searchParam, callback);

Contact Us

Contact our sales team or business advisors to help your business.

Technical Support

Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

7x24 Phone Support
Hong Kong, China
+852 800 906 020 (Toll Free)
United States
+1 844 606 0804 (Toll Free)
United Kingdom
+44 808 196 4551 (Toll Free)
Canada
+1 888 605 7930 (Toll Free)
Australia
+61 1300 986 386 (Toll Free)
EdgeOne hotline
+852 300 80699
More local hotlines coming soon