How do I get the list of shares from a Facebook post?

0

I'm trying to get the list of shares from a publication but it looks like something is wrong;

When I use 1365084196885691/sharedposts in the Facebook API I get the following JSON :

{
  "data": [
    {
      "story": "Leo Letto shared your photo.",
      "created_time": "2017-03-23T12:22:42+0000",
      "id": "1556800757888356_1901235313444897"
    },
    {
      "story": "Leo Letto shared your photo.",
      "created_time": "2017-03-22T03:38:47+0000",
      "id": "1556800757888356_1900507440184351"
    },
    {
      "story": "BluAnime shared their photo.",
      "created_time": "2017-03-22T03:14:53+0000",
      "id": "418054508255336_1366219626772148"
    },
    {
      "message": "https://www.facebook.com/BluAnime/photos/a.418514544875999.97023.418054508255336/1365084196885691/?type=3&theater",
      "story": "Positive shared your photo.",
      "created_time": "2017-03-21T00:22:36+0000",
      "id": "427369474003437_1476680245739016"
    }
  ],
  "paging": {
    "cursors": {
      "after": "MTQ3NjY4MDI0NTczOTAxNg==",
      "before": "MTkwMTIzNTMxMzQ0NDg5Nw=="
    }
  }
}

But the post in question currently has 43 Shares, why is facebook not returning the full list of users they shared?

    
asked by anonymous 23.03.2017 / 13:29

1 answer

1

This occurs in any well-modeled API, imagine the scenario where some APIs are requested more than 1 billion times a day (The Twitter API only in 2010 had to deal with 6 billion requests per day ): Returning to each GET just a JSON with an immense list with all the information would be chaos by amount of data transmitted, memory consumption etc. would be a much more difficult system to scale.

Paginations and limits

Paginations is a feature that avoids transmitting all data at once. Assuming there are 43 elements to the total and in your case 4 shares have been returned, on the "next page" there will be 4 more and so on until finished. Note that the 2.8 API API documentation along with your object is returned:

"paging": {
    "cursors": {
      "after": "MTM2NjIxOTYyNjc3MjE0OA==",
      "before": "MTMwMTk5MTYzOTg5MDU1OQ=="
    },
    "next": "https://graph.facebook.com/v2.8/1365084196885691/sharedposts?format=json&access_token=seu_token_gerado"
  }

"next" is the URL to send the GET request to get the "next page".

You can add the size limit of the share quantity list, for example you can get 10 items at once:

1365084196885691/sharedposts?limit=10

Note : Some APIs set a maximum limit, for example 100. If you send a limit equal to 200 you will still get 100 elements or you may get an error depending on the modeling.

GraphAPI

Facebook has Graph API Explorer, an easy way to test the API. Check out Facebook documentation on how to "navigate" between pages and set limits.

Using Graph API

    
07.04.2017 / 21:35