Skip to main content

Fetch Post Likes

The Fetch Post Likes feature in the Android Feed SDK allows users to retrieve information about the number of likes received by a specific post. By utilizing this functionality, developers can display the total number of likes on a post and provide users with social validation and engagement metrics.

Steps to fetch likes on a post

  1. Create a GetPostLikesRequest object using GetPostLikesRequest.Builder class by passing all the required parameters.
  2. Call getPostLikes() function using the instance of LMFeedClient.
  3. Process the response (LMResponse<GetPostLikesResponse>) as per your requirement.
CoroutineScope(Dispatchers.IO).launch {
// object of GetPostLikesRequest
val getPostLikesRequest = GetPostLikesRequest.Builder()
.postId("ENTER POST ID") // id of the post whose likes are fetched
.page(1) // page number for paginated data
.pageSize(10) // page size for paginated data
.build()
// get response (LMResponse<GetPostLikesResponse>)
val response = LMFeedClient.getInstance().getPostLikes(getPostLikesRequest)
if (response.success) {
// your function to process the response data
processGetPostLikesResponse(response.data)
} else {
// your function to process error message
processError(response.errorMessage)
}
}

Models

GetPostLikesRequest

VARIABLETYPEDESCRIPTIONOPTIONAL
postIdStringUnique id of the post whose likes are fetched.
pageIntPage number of paginated like data.
pageSizeIntPage size for paginated like data.

GetPostLikesResponse

VARIABLETYPEDESCRIPTIONOPTIONAL
likesList<Like>List of the likes on the post.
totalCountIntTotal count of likes on the post.
usersMap<String, User>Map of user unique id to user object.