List<String> userIDList = Arrays.asList("useridA", "useridB");V2TIMManager.getFriendshipManager().followUser
(userIDList, new V2TIMValueCallback<List<V2TIMFollowOperationResult>>() {@Overridepublic void onSuccess(List<V2TIMFollowOperationResult> followOperationResultList) {// Follow users successfully}@Overridepublic void onError(int code, String desc) {// Failed to follow users}});
NSArray *useridList = @[@"useridA", @"useridB"];[[V2TIMManager sharedInstance] followUser:userIDList succ:^(NSArray<V2TIMFollowOperationResult *> *resultList) {// Follow users succeeded} fail:^(int code, NSString *desc) {// Failed to follow users}];
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_;};V2TIMStringVector userIDList;userIDList.PushBack(u8"useridA");userIDList.PushBack(u8"useridB");auto callback = new ValueCallback<V2TIMFollowOperationResultVector>{};callback->SetCallback([=](const V2TIMFollowOperationResultVector& followOperationResultList) {// Follow users successfullydelete callback;},[=](int error_code, const V2TIMString& error_message) {// Failed to follow usersdelete callback;});V2TIMManager::GetInstance()->GetFriendshipManager()->FollowUser(userIDList, callback);
List<String> userIDList = Arrays.asList("useridA", "useridB");V2TIMManager.getFriendshipManager().unfollowUser
(userIDList, new V2TIMValueCallback<List<V2TIMFollowOperationResult>>() {@Overridepublic void onSuccess(List<V2TIMFollowOperationResult> followOperationResultList) {// Unfollow users successfully}@Overridepublic void onError(int code, String desc) {// Failed to unfollow users}});
NSArray *useridList = @[@"useridA", @"useridB"];[[V2TIMManager sharedInstance]unfollowUser
:userIDList succ:^(NSArray<V2TIMFollowOperationResult *> *resultList) {// Unfollow users successfully} fail:^(int code, NSString *desc) {// Failed to unfollow users}];
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_;};V2TIMStringVector userIDList;userIDList.PushBack(u8"useridA");userIDList.PushBack(u8"useridB");auto callback = new ValueCallback<V2TIMFollowOperationResultVector>{};callback->SetCallback([=](const V2TIMFollowOperationResultVector& followOperationResultList) {// Unfollow users successfullydelete callback;},[=](int error_code, const V2TIMString& error_message) {// Failed to unfollow usersdelete callback;});V2TIMManager::GetInstance()->GetFriendshipManager()->UnfollowUser
(userIDList, callback);
getMyFollowingList
API (Android / iOS & Mac / Windows) to pull the list of users you are following.{...String nextCursor = "";getMyFollowingList(nextCursor);...}public void getMyFollowingList(String nextCursor) {V2TIMManager.getFriendshipManager().getMyFollowingList(nextCursor, new V2TIMValueCallback<V2TIMUserInfoResult>() {@Overridepublic void onSuccess(V2TIMUserInfoResult v2TIMUserInfoResult) {StringBuilder stringBuilder = new StringBuilder();// Continue with the paged pullif (v2TIMUserInfoResult.getNextCursor().length() > 0) {// Continue paged pullgetMyFollowingList(v2TIMUserInfoResult.getNextCursor());...} else {// Pull complete}}@Overridepublic void onError(int code, String desc) {// Failed to pull}});}
- (void)getMyFollowingList:(NSString *)cursor {[[V2TIMManager sharedInstance] getMyFollowingList:cursor succ:^(NSString *nextCursor, NSArray<V2TIMUserFullInfo *> *userInfoList) {if (nextCursor.length > 0) {// Continue with the paged pull[self getMyFollowingList:nextCursor];//...} else {// Pull complete}} fail:^(int code, NSString *desc) {// Failed to pull}];}
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_;};V2TIMString nextCursor = u8"";void GetMyFollowingList(const V2TIMString& nextCursor) {auto callback = new ValueCallback<V2TIMUserInfoResult>{};callback->SetCallback([=](const V2TIMUserInfoResult& userInfoResult) {if (userInfoResult.nextCursor.Length() > 0) {// Continue with the paged pullGetMyFollowingList(userInfoResult.nextCursor);...} else {// Pull complete}delete callback;},[=](int error_code, const V2TIMString& error_message) {// Failed to pulldelete callback;});V2TIMManager::GetInstance()->GetFriendshipManager()->GetMyFollowingList(nextCursor, callback);}
getMyFollowersList
API (Android / iOS & Mac / Windows) to fetch your own list of follower users.{...String nextCursor = "";getMyFollowersList
(nextCursor);...}public voidgetMyFollowersList
(String nextCursor) {V2TIMManager.getFriendshipManager().getMyFollowersList
(nextCursor, new V2TIMValueCallback<V2TIMUserInfoResult>() {@Overridepublic void onSuccess(V2TIMUserInfoResult v2TIMUserInfoResult) {StringBuilder stringBuilder = new StringBuilder();if (v2TIMUserInfoResult.getNextCursor().length() > 0) {// Continue with the paged pullgetMyFollowersList
(v2TIMUserInfoResult.getNextCursor());...} else {// Pull complete}}@Overridepublic void onError(int code, String desc) {// Failed to pull}});}
- (void)getMyFollowersList
:(NSString *)cursor {[[V2TIMManager sharedInstance]getMyFollowersList
:cursor succ:^(NSString *nextCursor, NSArray<V2TIMUserFullInfo *> *userInfoList) {if (nextCursor.length > 0) {// Continue with the paged pull[selfgetMyFollowersList
:nextCursor];//...} else {// Pull complete}} fail:^(int code, NSString *desc) {// Failed to pull}];}
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_;};V2TIMString nextCursor = u8"";void GetMyFollowersList(const V2TIMString& nextCursor) {auto callback = new ValueCallback<V2TIMUserInfoResult>{};callback->SetCallback([=](const V2TIMUserInfoResult& userInfoResult) {if (userInfoResult.nextCursor.Length() > 0) {// Continue with the paged pullGetMyFollowersList(userInfoResult.nextCursor);...} else {// Pull complete}delete callback;},[=](int error_code, const V2TIMString& error_message) {// Failed to pulldelete callback;});V2TIMManager::GetInstance()->GetFriendshipManager()->GetMyFollowersList(nextCursor, callback);}
nextCursor
parameter of the API with ""
. After a successful callback, if the returned nextCursor
is not ""
, you can input this value to fetch again, until nextCursor
returns ""
, indicating that the fetch is complete.getMutualFollowersList
API (Android / iOS & Mac / Windows) to pull the list of users who mutually follow each other (Users who mutually follow can find each other in their following and followers lists).{...String nextCursor = "";getMutualFollowersList(nextCursor);...}public void getMutualFollowersList(String nextCursor) {V2TIMManager.getFriendshipManager().getMutualFollowersList(nextCursor, new V2TIMValueCallback<V2TIMUserInfoResult>() {@Overridepublic void onSuccess(V2TIMUserInfoResult v2TIMUserInfoResult) {StringBuilder stringBuilder = new StringBuilder();if (v2TIMUserInfoResult.getNextCursor().length() > 0) {// Continue with the paged pullgetMutualFollowersList(v2TIMUserInfoResult.getNextCursor());...} else {// Pull complete}}@Overridepublic void onError(int code, String desc) {// Failed to pull}});}
- (void)getMutualFollowersList:(NSString *)cursor {[[V2TIMManager sharedInstance] getMutualFollowersList:cursor succ:^(NSString *nextCursor, NSArray<V2TIMUserFullInfo *> *userInfoList) {if (nextCursor.length > 0) {// Continue with the paged pull[self getMutualFollowersList:nextCursor];//...} else {// Pull complete}} fail:^(int code, NSString *desc) {// Failed to pull}];}
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_;};V2TIMString nextCursor = u8"";void GetMutualFollowersList(const V2TIMString& nextCursor) {auto callback = new ValueCallback<V2TIMUserInfoResult>{};callback->SetCallback([=](const V2TIMUserInfoResult& userInfoResult) {if (userInfoResult.nextCursor.Length() > 0) {// Continue with the paged pullGetMutualFollowersList(userInfoResult.nextCursor);...} else {// Pull complete}delete callback;},[=](int error_code, const V2TIMString& error_message) {// Failed to pulldelete callback;});V2TIMManager::GetInstance()->GetFriendshipManager()->GetMutualFollowersList(nextCursor, callback);}
nextCursor
parameter of the API with ""
. After a successful callback, if the returned nextCursor
is not ""
, you can input this value to fetch again, until nextCursor
returns ""
, indicating that the fetch is complete.getUserFollowInfo
API (Android / iOS & Mac / Windows) to get the count of following/followers/mutual followers for specific users.followingCount
, followersCount
, and mutualFollowersCount
of V2TIMFollowInfo
(Android / iOS & Mac / Windows) .List<String> userIDList = Arrays.asList("useridA", "useridB");V2TIMManager.getFriendshipManager().getUserFollowInfo(userIDList, new V2TIMValueCallback<List<V2TIMFollowInfo>>() {@Overridepublic void onSuccess(List<V2TIMFollowInfo> followInfoList) {// Obtained successfullyfor (V2TIMFollowInfo followInfo : V2TIMFollowInfoList) {if (followInfo.getResultCode() == 0) {// Here, you can get the count of following/followers/mutual followers corresponding to the user, followInfo.getUserID().// That is, followInfo.getFollowingCount(), followInfo.getFollowersCount() and followInfo.getMutualFollowersCount().}}}@Overridepublic void onError(int code, String desc) {// Failed to obtain}});
NSArray *useridList = @[@"useridA", @"useridB"];[[V2TIMManager sharedInstance] getUserFollowInfo:userIDList succ:^(NSArray<V2TIMFollowInfo *> *resultList) {// Obtained successfullyfor (V2TIMFollowInfo *result in resultList) {if (result.resultCode == 0) {// Here, you can get the count of following/followers/mutual followers corresponding to the user, result.userID.// That is, result.followingCount, result.followersCount, and result.mutualFollowersCount.}}} fail:^(int code, NSString *desc) {// Failed to obtain}];
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_;};V2TIMStringVector userIDList;userIDList.PushBack(u8"useridA");userIDList.PushBack(u8"useridB");auto callback = new ValueCallback<V2TIMFollowInfoVector>{};callback->SetCallback([=](const V2TIMFollowInfoVector& followInfoList) {// Obtained successfullyfor (size_t i = 0; i < followInfoList.Size(); ++i) {if (followInfoList[i].resultCode == 0) {// Here, you can get the count of following/followers/mutual followers for the user, followInfoList[i].userID.// That is, followInfoList[i].followingCount, followInfoList[i].followersCount, and followInfoList[i].mutualFollowersCount.}}delete callback;},[=](int error_code, const V2TIMString& error_message) {// Failed to obtaindelete callback;});V2TIMManager::GetInstance()->GetFriendshipManager()->GetUserFollowInfo
(userIDList, callback);
checkFollowType
API (Android / iOS & Mac / Windows) to check your following relationship with specified users.followType
of V2TIMFollowTypeCheckResult
(Android / iOS & Mac / Windows):V2TIMFollowTypeCheckResult.followType | Relationship with yourself |
V2TIM_FOLLOW_TYPE_NONE | No following relationship |
V2TIM_FOLLOW_TYPE_IN_MY_FOLLOWING_LIST | The user is only in my following list |
V2TIM_FOLLOW_TYPE_IN_MY_FOLLOWERS_LIST | The user is only in my followers list |
V2TIM_FOLLOW_TYPE_IN_BOTH_FOLLOWERS_LIST | Mutually follow with the user (the user is both in my following list and in my followers list) |
List<String> userIDList = Arrays.asList("useridA", "useridB");V2TIMManager.getFriendshipManager().checkFollowType(userIDList, new V2TIMValueCallback<List<V2TIMFollowTypeCheckResult>>() {@Overridepublic void onSuccess(List<V2TIMFollowTypeCheckResult> followTypeCheckResultList) {// Successfully checked the follow relationshipfor (V2TIMFollowTypeCheckResult followTypeCheckResult : followTypeCheckResultList) {if (followTypeCheckResult.getResultCode() == 0) {// Here, you can get the relationship with the user followTypeCheckResult.getUserID(), the follow type followTypeCheckResult.getFollowType()}}}@Overridepublic void onError(int code, String desc) {// Failed to check the follow relationship}});
NSArray *useridList = @[@"useridA", @"useridB"];[[V2TIMManager sharedInstance] checkFollowType:userIDList succ:^(NSArray<V2TIMFollowTypeCheckResultListSucc *> *resultList) {// Successfully checked the follow relationshipfor (V2TIMFollowTypeCheckResult *result in resultList) {if (result.resultCode == 0) {// Here, you can get the relationship with the user result.userID, the follow type result.followType}}} fail:^(int code, NSString *desc) {// Failed to check the follow relationship}];
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_;};V2TIMStringVector userIDList;userIDList.PushBack(u8"useridA");userIDList.PushBack(u8"useridB");auto callback = new ValueCallback<V2TIMFollowTypeCheckResultVector>{};callback->SetCallback([=](const V2TIMFollowTypeCheckResultVector& followTypeCheckResultList) {// Successfully checked the follow relationshipfor (size_t i = 0; i < followTypeCheckResultList.Size(); ++i) {if (followTypeCheckResultList[i].resultCode == 0) {// Here, you can get the relationship with the user followTypeCheckResultList[i].userID, the follow type followTypeCheckResultList[i].followType}}delete callback;},[=](int error_code, const V2TIMString& error_message) {// Failed to check the follow relationshipdelete callback;});V2TIMManager::GetInstance()->GetFriendshipManager()->FollowUser(userIDList, callback);
checkFollowType
API is up to 20 calls within 5 seconds, and each call can support up to 100 users.List Change Notification | Description |
When the isAdd in the notification is true , it signifies a notification for adding a user to the list, and at this time, the complete user profile is returnedWhen the isAdd in the notification is false , it signifies a notification for deleting a user from the list, and at this time, only the user ID is included in the returned user profile | |
| |
Mutual Followers List Change Notification onMutualFollowersListChanged | |
addFriendListener
(Android / iOS and macOS / Windows) beforehand to add a relationship event listener.Alice
and Bob
. During the process of mutual following, the related list change notifications and relationship changes are as follows:Event | Alice | Bob | ||
| Notifications received | Relationship with Bob | Notifications received | Relationship with Alice |
Alice follows Bob | ||||
Bob follows Alice | |
Alice
and Bob
, who are mutual followers, during the process of mutually unfollowing, the related list change notifications and relationship changes are as follows:Event | Alice | Bob | ||
| Notifications received | Relationship with Bob | Notifications received | Relationship with Alice |
Alice unfollows Bob | | | ||
Bob unfollows Alice |
V2TIMFriendshipListener v2TIMFriendshipListener = new V2TIMFriendshipListener() {@Overridepublic void onMyFollowingListChanged(List<V2TIMUserFullInfo> userInfoList, boolean isAdd) {if (isAdd) {// Receive notification of users added to following list} else {// Receive notification of users deleted from following list}}@Overridepublic void onMyFollowersListChanged(List<V2TIMUserFullInfo> userInfoList, boolean isAdd) {if (isAdd) {// Receive notification of users added to followers list} else {// Receive notification of users deleted from followers list}}@Overridepublic void onMutualFollowersListChanged(List<V2TIMUserFullInfo> userInfoList, boolean isAdd) {if (isAdd) {// Receive notification of users added to mutual followers list} else {// Receive notification of users deleted from mutual follow list}}};// Add a relationship chain listenerV2TIMManager.getFriendshipManager().addFriendListener(v2TIMFriendshipListener);
// Add a relationship event listener[[V2TIMManager sharedInstance] addFriendListener:self];- (void)onMyFollowingListChanged:(NSArray<V2TIMUserFullInfo *> *)userInfoList isAdd:(BOOL)isAdd {if (isAdd) {// Receive notification of users added to following list} else {// User deletion notification from following list}}- (void)onMyFollowersListChanged:(NSArray<V2TIMUserFullInfo *> *)userInfoList isAdd:(BOOL)isAdd {if (isAdd) {// Receive notification of users added to followers list} else {// Receive notification of users deleted from followers list}}- (void)onMutualFollowersListChanged:(NSArray<V2TIMUserFullInfo *> *)userInfoList isAdd:(BOOL)isAdd {if (isAdd) {// Receive notification of users added to mutual followers list} else {// Receive notification of users deleted from mutual followers list}}
class FriendshipListener final : public V2TIMFriendshipListener {public:FriendshipListener() = default;~FriendshipListener() override = default;void OnMyFollowingListChanged(const V2TIMUserFullInfoVector &userInfoList, bool isAdd) override {if (isAdd) {// Receive notification of users added to following list} else {// Receive notification of users deleted from following list}}void OnMyFollowersListChanged(const V2TIMUserFullInfoVector &userInfoList, bool isAdd) override {if (isAdd) {// Receive notification of users added to followers list} else {// Receive notification of users deleted from followers list}}void OnMutualFollowersListChanged(const V2TIMUserFullInfoVector &userInfoList, bool isAdd) override {if (isAdd) {// Receive notification of users added to mutual followers list} else {// Receive notification of users deleted from mutual followers list}}// Other member functions ...};// Add a relationship event listener. Note that the lifespan of the friendshipListener must be maintained before removing the listener to ensure event callbacks are receivedFriendshipListener friendshipListener;V2TIMManager::GetInstance()->GetFriendshipManager()->AddFriendListener(&friendshipListener);
Was this page helpful?