Get posts with insights from a single API call - Facebook Graph API

Viewed 5244

I'm wondering if there's a way to get recent 10 posts with some of their insights (reactions, reach, views ..etc) from a single API call.

Currently what I'm doing is getting recent 10 posts and looping through their IDs to get their insights. But this slows down the request.

I'm expecting a response like this

{
  "posts": {
    "data": [
      {
        "story": "Cyborgs shared Society of Computer Sciences - SUSL's post.",
        "id": "1078877558819703_1767294393311346",
        "views": "123",
        "reach": "435",
      },
      {
        "story": "Cyborgs shared Gamers On Board's video.",
        "id": "1078877558819703_1766615263379259",
        "views": "23",
        "reach": "45",
      },
      {
        "story": "Cyborgs was feeling motivated.",
        "id": "1078877558819703_1547214361986018"
        "views": "243",
        "reach": "34",
      },
    ],

  }
}

So, as you can see along with post list, views and reach values are also coming relevant to each object.

So, is this possible ? How ?

1 Answers

Yes. It is possible to do that.

Here, I'm attaching my graph API URL through which you can get all the posts of the selected page along with the insights.

You can specify below request in FB graph API tool or any another SDK.

/{page-id}/posts?fields=insights.metric(post_impressions_fan,post_engaged_users)

You can specify as much as insights metrics with the comma separated.

You can find more insights metrics at below URL. https://developers.facebook.com/docs/graph-api/reference/v3.0/insights

Related