Skip to main content

Fetch Post Likes

The getPostLikes() function 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 Get Post Likes

  1. Create an instance of GetPostLikesRequest with the required parameters: postId for the post to retrieve likes, and optionally, page and pageSize for pagination.
  2. Call the getPostLikes() function using the instance of the LMFeedClient class, passing the request as a parameter.
  3. Use the response as per your requirement.
// Create an instance of GetPostLikesRequest
GetPostLikesRequest request = (GetPostLikesRequestBuilder()
..page(1)
..pageSize(10)
..postId("post_id"))
.build();

// Get the response from calling the function
final GetPostLikesResponse postLikesResponse = await lmFeedClient.getPostLikes(postLikesRequest);

// Process the response, as per requirement
if (postLikesResponse.success) {
// your function to handle successful retrieval of post likes
handlePostLikesSuccess(postLikesResponse.likes, postLikesResponse.totalCount, postLikesResponse.users);
} else {
// your function to handle error message
handlePostLikesError(postLikesResponse.errorMessage);
}

Models

GetPostLikesRequest

List of parameters for the GetPostLikesRequest class

VariableTypeDescriptionOptional
postIdStringID of the post to retrieve likes
pageintPage number for pagination
pageSizeintNumber of items per page

GetPostLikesResponse

List of parameters for the GetPostLikesResponse class

VariableTypeDescriptionOptional
successboolAPI success status
errorMessageStringError message in case of failure
likesList<Like>List of likes for the post
totalCountintTotal count of likes for the post
usersMap<String, User>Map of user UUIDs to User entities