Sign up ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

How can you retrieve a list items "Likes" using the JSOM or REST API's? I know there is the following method: SP.Social.SocialFeedManager.getAllLikers(postId), but in testing I was not successful using the "posts" item id as the methods postId.

Any help or direction as to how this is done would be greatly appreciated.

share|improve this question
Where you using the posts ID (around two or three digits long) or its GUID? – Robert Lindgren May 7 '13 at 5:49
Hi Robert, I did try both methods, passing in the int ID as well as the item GUID. Maybe I am not loading my client context correctly? If you could provide an example, I'd greatly appreciate it. Thanks! – MarcusTheShogun May 7 '13 at 12:02
Better you copy paste in your code here so everyone can see it, and maybee spot some errors :) – Robert Lindgren May 7 '13 at 12:06

3 Answers 3

I found an article (link below) that had a code snippet to get all likers (Graphic). Sounded like it might be useful for your problem.

enter image description here

share|improve this answer

I found a CSOM example here that's simply pinging a list item's "AverageRating", "RatingCount", and "Ratings" props to give you the item's rating info. The challenge though is in converting this to JSOM...

using (ClientContext ctx = new ClientContext("https://yourSiteUrl")){
    Web w = ctx.Web;
    List l = w.Lists.GetByTitle("yourListName");

    CamlQuery cq = CamlQuery.CreateAllItemsQuery();
    ListItemCollection lic = l.GetItems(cq);

    ctx.Load(lic, items => 
        item => item.Id,
        item => item["AverageRating"],
        item => item["RatingCount"],
        item => item["Ratings"]));

     foreach (ListItem li in lic){
share|improve this answer

I found the following JSON code in this posting demonstrating how to add 'Like' functionality to a publishing page with Javascript. Presumably, the 'LikedBy' property would also be exposed for any list/library with ratings setting enabled.

    var likepage = {
    //Likes the current page. 
    LikePage: function () {
        likepage.getUserLikedPage(function(likedPage, likeCount) {

            var aContextObject = new SP.ClientContext();
            EnsureScriptFunc('reputation.js', 'Microsoft.Office.Server.ReputationModel.Reputation', function() {
                        _spPageContextInfo.pageListId.substring(1, 37),
                        _spPageContextInfo.pageItemId, !likedPage);

                    function() {
                        var elements = document.getElementsByClassName('likecount');
                        if (likedPage) {
                        } else {
                        for (var i = 0; i < elements.length;i++) {
                            elements[i].innerHTML = likeCount;
                    }, function(sender, args) {
                        // Custom error handling if needed


    // Checks if the user already liked the page, and returns the number of likes. 
    getUserLikedPage: function (cb) {
        var context = new SP.ClientContext(_spPageContextInfo.webServerRelativeUrl);
        var list = context.get_web().get_lists().getById(_spPageContextInfo.pageListId);
        var item = list.getItemById(_spPageContextInfo.pageItemId);

        context.load(item, "LikedBy", "ID", "LikesCount");
        context.executeQueryAsync(Function.createDelegate(this, function (success) {
            // Check if the user id of the current users is in the collection LikedBy. 
            var $v_0 = item.get_item('LikedBy');
            if (!SP.ScriptHelpers.isNullOrUndefined($v_0)) {
                for (var $v_1 = 0, $v_2 = $v_0.length; $v_1 < $v_2; $v_1++) {
                    var $v_3 = $v_0[$v_1];
                    if ($v_3.$1E_1 === _spPageContextInfo.userId) {
                        cb(true, item.get_item('LikesCount'));
            cb(false, item.get_item('LikesCount'));
            Function.createDelegate(this, function (sender, args) { 
            //Custom error handling if needed 
    initialize: function () {
        var elements = document.getElementsByClassName('likecount');
        likepage.getUserLikedPage(function(likedPage, likesCount) {
            for (var i = 0; i < elements.length; i++) {
                elements[i].innerHTML = likesCount;
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.