2

I want to select the specific insights I need from within a nested query

I can get the desired fields (post_impressions and post_stories) when searching a single post with its id...

<postId>/insights/post_impressions,post_stories

But can I retrieve the same fields from a list of posts?

Something like this...

<pageId>/posts?fields=id,name,insights{post_impressions,post_stories}

Basically I'm trying to get a few fields from a post as well as a couple insights fields in one call.

kurtcorbett
  • 1,355
  • 1
  • 12
  • 17

2 Answers2

8

This is the correct syntax that you need:

{pageId}/feed?fields=insights.metric(post_impressions,post_impressions_unique,...)
buczek
  • 2,011
  • 7
  • 29
  • 40
1

But can I retrieve the same fields from a list of posts?

If you have a couple of post ids, then you can request that data for all of them by using this syntax:

/insights/post_impressions,post_stories?ids=id1,id2,id3,…

https://developers.facebook.com/docs/graph-api/using-graph-api/v2.5#multirequests

CBroe
  • 91,630
  • 14
  • 92
  • 150
  • Do you know if facebook guarantees that the result sets will come back in the same order that I requested them? – kurtcorbett Nov 13 '15 at 07:57
  • No, I don’t. But the ids are used as keys in the resulting data structure, so you will know which entry is for which post that way. – CBroe Nov 13 '15 at 10:19
  • Ok. My original hope was that i could get a select set of insights from each post in a feed of posts, therefore eliminating the need to do multiple server calls to retrieve the posts then to query the insights by post ids, but it appears that isn't currently possible. Thanks for your help. – kurtcorbett Nov 13 '15 at 23:00
  • Well, you can eliminate the number of HTTP requests you have to make, by using [Batch Requets](https://developers.facebook.com/docs/graph-api/making-multiple-requests). – CBroe Nov 14 '15 at 00:11