Get the friend list
Paginate the friend list for the authenticated user and synchronize friendship events in real time.
Paginate the friend list for the authenticated account to prevent excessive memory and network overhead. Each record contains basic user profile information alongside friend-specific attributes like remarks and source details.
Code example
OpenIMClient.getInstance().friendshipManager.getFriendListPage(
new OnBase<List<UserInfo>>() {
@Override
public void onSuccess(List<UserInfo> friends) {
// Update friend list UI using friends
}
@Override
public void onError(int code, String error) {
// Handle error
}
},
0,
40,
true
);Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
base | OnBase<List<UserInfo>> | Yes | Callback delivering the asynchronous operation result. |
offset | int | Yes | Zero-based paging offset; pass 0 for the initial page. |
count | int | Yes | Number of friend records to return in this page. |
filterBlack | boolean | Yes | When true, automatically filters out blocked users; when false, includes them. |
Return value
The successful callback returns the current page as List<UserInfo>. Deduplicate and merge items into your local cache using userID as the unique key. When the returned item count is less than count, the end of the list has been reached.
Commonly used fields within the friend records include:
| Field | Description |
|---|---|
userID | Global user ID of the friend. |
nickname | Public display nickname of the friend. |
faceURL | Avatar URL of the friend. |
remark | Private remark alias set by the authenticated user. |
ex | Custom relationship extension metadata. |
addSource | Channel or source through which friendship was established. |
operatorUserID | User ID of the operator who initiated or approved the relationship. |
createTime | Unix timestamp when friendship was established. |
State changes after the call
When friends are added, modified, or removed, the SDK dispatches real-time events via OnFriendshipListener. Use userID as the primary key to merge updates or delete entries:
@Override
public void onFriendAdded(FriendInfo friend) {
// New friend added; insert into the list or refresh UI
}
@Override
public void onFriendInfoChanged(FriendInfo friend) {
// Nickname, remark, or avatar updated; refresh the item matching friend.getUserID()
}
@Override
public void onFriendDeleted(FriendInfo friend) {
// Friendship terminated; remove the entry matching friend.getUserID() from local cache
}Was this page helpful?