Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Facebook share/like/comment count of URL

Prior to today, I used the following URL to get the Facebook share/like/comment count of a URL:

https://api.facebook.com/method/links.getStats?format=json&urls=http://stackoverflow.com/

Today, Facebook removed this feature. So now I'm using this:

https://graph.facebook.com/v2.7?emc=rss&fields=og_object{engagement},share&access_token=<ACCESS_TOKEN_GOES_HERE>&id=http://stackoverflow.com/

Which outputs:

{
    "og_object": {
        "engagement": {
            "count": 45267,
            "social_sentence": "45K people like this."
        },
        "id": "10150180465825637"
    },
    "share": {
        "comment_count": 12,
        "share_count": 45267
    },
    "id": "http://stackoverflow.com/"
}

The problem is, share_count is the total of likes + comments + shares (as far as I know).

Is there a way to get the number of likes, comments, and shares separately?

like image 687
user6724149 Avatar asked Dec 19 '22 14:12

user6724149


2 Answers

Looks like a bug in fb-api.

My solution:

  1. receive the number of shares/comments as you describe in your question with

    graph.facebook.com/?fields=og_object{id},share&id=https://stackoverflow.com/

  2. save shares/comments count

  3. save fb object-id of url

    og_object->id

  4. get likes count with (max limit is 1000, then you can use paging):

    graph.facebook.com/OBJECT_ID/likes?access_token=ACCESS_TOKEN&pretty=1&limit=1000

UPD 2016-08-22

I found a solution that allows you to get the number of likes/reposts/comments in one step:

https://graph.facebook.com/?fields=og_object{likes.limit(0).summary(true)},share&ids=http://google.com,http://twitter.com

like image 152
dim Avatar answered Jan 10 '23 11:01

dim


It is not currently possible. Facebook is adding likes/shares/comments for URLs and returning them as shared_count. Not possible to return correct number of individual likes/shares/comments, and that is not clear in the Graph API documentation. Not clear if it is a bug or a documentation error.

The old Rest API that provided this data was turned off on the 18th August.

There is a comment from a Facebook engineer explaining this in reply to a bug report, in the answer to this Stack Overflow question: Getting Facebook Share, Like and Comment Counts for a Given URL with API Graph v2.6

You can also subscribe to this bug report at Facebook, but is a bit old with still no solution: https://developers.facebook.com/bugs/748651458568287/

like image 23
joao Avatar answered Jan 10 '23 11:01

joao