How to know whether or not you are liking SocialPost - Sharepoint 2013 Client Object API

vendredi 18 octobre 2013

Today, I'd to speek about giving users the possibility to like SharePoint 2013 posts using the Client Object API.
You'll need to instanciate your SocialFeedManager with your context, and then call the "LikePost" method with the postId you would 'like'.


Code:
public SocialThread LikeThisPost(string SharePointWebUrl, string PostId)
 { 
 SocialFeedManager feedManager = new SocialFeedManager(ctx);
 ClientResult thread = feedManager.LikePost(PostId);
 ctx.ExecuteQuery();
 return thread.Value;
 }

This method returns the whole thread, containing the root post, all the replies and many other attributes.
Maybe you'll need to parse this result into your business post object.

From the SocialPost's LikerInfo collection you could know if the current user likes the post or not.
No need to try to implement some logic for getting this, SharePoint has already done this for you.


Code:
bool CurrentUserLikesThis = socialPost.LikerInfo.IncludesCurrentUser;

Copyright @ 2013 Nizar Joober - I'm SharingPoints. Designed by Templateism

Top articles