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
- Create a GetPostLikesRequest object using
GetPostLikesRequest.Builder
class by passing all the required parameters. - Call
getPostLikes()
function using the instance ofLMFeedClient
. - 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
VARIABLE | TYPE | DESCRIPTION | OPTIONAL |
---|---|---|---|
postId | String | Unique id of the post whose likes are fetched. | |
page | Int | Page number of paginated like data. | |
pageSize | Int | Page size for paginated like data. |
GetPostLikesResponse
VARIABLE | TYPE | DESCRIPTION | OPTIONAL |
---|---|---|---|
likes | List<Like> | List of the likes on the post. | |
totalCount | Int | Total count of likes on the post. | |
users | Map<String, User> | Map of user unique id to user object. |