How do I get the share list for a Facebook post?

Asked

Viewed 1,496 times

0

I’m trying to get a list of shares from a post but it looks like something’s wrong;

When I use the 1365084196885691/sharedpostsin 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 facebook is not returning the full list of users who shared?

1 answer

1

This occurs in any well-modeled API, imagine the scenario where some Apis are ordered more than 1 billion times a day (Twitter’s API only in 2010 had to deal with 6 billion requests per day): Return to each GET only a JSON with a huge 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 in total and in your case 4 shares has been returned, on the "next page" there will be 4 more and so on until you finish. Note that by documenting the Facebook API 2.8 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".

It is possible to add the size limit of the share amount list, for example you can get 10 items at once:

1365084196885691/sharedposts?limit=10

Note: Some Apis establish a maximum Limits, for example 100. If you submit a Limits 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 the Facebook documentation on how to "browse" between pages and set limits.

Using Graph API

Browser other questions tagged

You are not signed in. Login or sign up in order to post.