16

What's the best way to get the like, share, comment count for a post?

I'm trying via FQL but it doesn't seem to give any data when the URL is a FB post URL:

SELECT like_count, comment_count, share_count FROM link_stat WHERE url="https://www.facebook.com/Macklemore/posts/10153256675935268"

When I get the post info via the Graph API Explorer:

386050065267_10153256675935268

It gives me the like count and share count and I can get the comment count via 386050065267_10153256675935268/comments?summary=true

{
  "id": "386050065267_10153256675935268", 
  "from": {
    "category": "Musician/band", 
    "name": "Macklemore", 
    "id": "386050065267"
  }, 
  "message": "We’re playing a FREE show in November to celebrate the new Microsoft Store opening in Jacksonville, Florida. Come see us! Info here: http://msft.it/STJevent\n\nThursday, November 21, 2013\n10:00 p.m.\nStart lining up for your chance to attend the show on Saturday.\nLocation: Outdoors behind Oakley, near Dick’s Sporting Goods.", 
  "actions": [
    {
      "name": "Comment", 
      "link": "https://www.facebook.com/386050065267/posts/10153256675935268"
    }, 
    {
      "name": "Like", 
      "link": "https://www.facebook.com/386050065267/posts/10153256675935268"
    }
  ], 
  "privacy": {
    "value": ""
  }, 
  "type": "status", 
  "status_type": "mobile_status_update", 
  "created_time": "2013-09-26T16:30:23+0000", 
  "updated_time": "2013-09-27T20:39:45+0000", 
  **"shares": {
    "count": 274
  },** 
  "likes": {
    "data": [
      {
        "name": "Jabson Ramos", 
        "id": "100005418486411"
      }, 
      {
        "name": "Sophia Belen Parada Andrades", 
        "id": "100002552653152"
      }, 
      {
        "name": "Oli Barrera", 
        "id": "100001718791443"
      }, 
      {
        "name": "Viktoria Martinez", 
        "id": "1697663024"
      }
    ], 
    **"count": 3345**
  }, 
  "comments": {
    "data": [
      {
        "id": "10153256675935268_43537841", 
        "from": {
          "name": "Vu Thai", 
          "id": "1338690172"
        }, 
        "message": "Sean Viray Matt Win Soo... about my birthday weekend...", 
        "message_tags": [
          {
            "id": "75311036", 
            "name": "Sean Viray", 
            "type": "user", 
            "offset": 0, 
            "length": 10
          }, 
          {
            "id": "25113189", 
            "name": "Matt Win", 
            "type": "user", 
            "offset": 11, 
            "length": 8
          }
        ], 
        "can_remove": false, 
        "created_time": "2013-09-26T16:31:03+0000", 
        "like_count": 4, 
        "user_likes": false
      }, 
      .....
    ], 
    "paging": {
      "cursors": {
        "after": "MjY=", 
        "before": "MQ=="
      }, 
      "next": "https://graph.facebook.com/386050065267_10153256675935268/comments?limit=25&after=MjY="
    }
  }
}

Weird thing is when I run that query in my app I don't get the share count or like count. Am I doing something wrong? Is the data in the explorer different from what apps have access to?

I know I can get the like count via 386050065267_10153256675935268/likes?summary=true

Biggest thing would be the missing share count.

So summary,

Can you get these stats via FQL? If not, how can you obtain the share count via the graph API?

Stéphane Bruckert
  • 21,706
  • 14
  • 92
  • 130
DamnSemicolon
  • 261
  • 1
  • 3
  • 10
  • 1
    The `link_stat` table is for external URLs only. And for the like count of a post, please see the Oct. 2, 2013 breaking changes in the [roadmap](https://developers.facebook.com/roadmap/) – CBroe Sep 28 '13 at 11:08
  • thanks. so is there any way to get the share count of a post via the graph api? – DamnSemicolon Sep 29 '13 at 18:20
  • Please check your answer at here: http://stackoverflow.com/questions/9728279/getting-the-facebook-like-share-count-for-a-given-url/35062056#35062056 – Atif Tariq Jan 28 '16 at 13:11

3 Answers3

41
POST_ID?fields=likes.summary(true),comments.summary(true),shares

Result:

{
  "shares": {
    "count": 272            //share count
  }, 
  "likes": {
    "data": [

    ], 
    "paging": {

    }, 
    "summary": {
      "total_count": 3453   //like count
    }
  }, 
  "comments": {
    "data": [

    ], 
    "paging": {

    }, 
    "summary": {
      "total_count": 255    //comment count
    }
  }
}
Stéphane Bruckert
  • 21,706
  • 14
  • 92
  • 130
  • 1
    How would you write this as an URL? – daremkd Jan 20 '14 at 10:24
  • Thank you for the comprehensive answer. I was looking for a simple solution, not sure if you understood me. Using the asker example, you could obtain this JSON data by going here: http://graph.facebook.com/386050065267_10153256675935268/comments?summary=true my question was more on how would you construct an URL HTTP GET request with FQL, what would be the URL equivalent to the one I just gave that will produce the JSON in your answer (from post ID)? Very comprehensive answer by the way, doubt anyone will be able to match it. – daremkd Jan 20 '14 at 12:32
  • btw can't you just use the post ID alone? I found that works as well. – daremkd Jan 20 '14 at 12:55
  • Oh... if that's only it, just replace `YOUR_ACCESS_TOKEN` by your own access token in [that](https://graph.facebook.com/fql?q=SELECT%20like_info.like_count,%20comment_info.comment_count,%20share_count%20FROM%20stream%20WHERE%20post_id%20=%20%22386050065267_10153256675935268%22&access_token=YOUR_ACCESS_TOKEN) link. – Stéphane Bruckert Jan 20 '14 at 13:26
  • Answer not outdated. Cant find any way now. –  Jun 20 '15 at 16:10
  • Please find an updated answer with a way to do it with Graph. – Stéphane Bruckert Jun 20 '15 at 16:33
  • where does facebook hiding documentation for all these parameters, I was searching for almost 4 hours.. thanks – Vignesh Sep 01 '15 at 13:28
  • the shares field no longer works for me on any graph call (v2 or 2.5), but it does have a sharedposts field, which only returns public shares based on your access token, so is completely inaccurate for just getting a count. The summary(true) trick doesn't work on it either. – Scott Flack Mar 10 '16 at 04:03
5

You can use facebook graph api like https://graph.facebook.com/?ids=http://mycodingtricks.com and it will return a json code like

{  
    "http://mycodingtricks.com":{  
        "id":"http://mycodingtricks.com",
        "shares":1
    }
}

I have developed my own php script on which you can all social count using that api. http://mycodingtricks.com/share/social.php?url=YOUR-URL-HERE and it will return data like:

{  
    "facebook":[  
        {  
            "share_count":1,
            "like_count":0,
            "comment_count":0,
            "total_count":1,
            "click_count":0,
            "comments_fbid":567687199998199,
            "commentsbox_count":0
        }
    ],
    "googleplus":10,
    "twitter":3,
    "buffer":0,
    "pinterest":0,
    "stumblupon":1,
    "reddit":"<html><body><h1>403 Forbidden<\/h1>\nRequest forbidden by administrative rules.\n<\/body><\/html>\n",
    "linkedin":0
}

But if you wants to use on your own Here is a complete article about how to count facebook share,like and all. http://mycodingtricks.com/php/2-ways-to-count-facebook-likes-shares-and-comments-using-php/

Shubham Kumar
  • 1,221
  • 14
  • 5
3

FQL is now depreciated. Here's how to do it using the 2.x API:

get /1000076132681/posts?limit=3&fields=object_id,likes.summary(true),comments.summary(true)

This results in the xml, for example:

"summary": {
   "total_count": 80
 }

And in case you need the larger-size picture url as well, check out

?fields=full_picture,attachments
Kevin
  • 4,225
  • 2
  • 37
  • 40
  • How do you run this query using a SDK, for instance PHP? my request looks like this: $pageId . "?fields=feed{message,description,type,icon,link,likes{total_count}} – Buffalo Jul 04 '16 at 15:47