Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Post Insights for multiple posts in one call using Graph Api 2.7

I am trying to get post insights for a page feed using Facebook Graph API version 2.7 ..

If I only write:

'[Page ID]/feed?fields=insights'

It asks for metric, which indicates it should work... But when specifying a metric:

'[Page ID]/feed?fields=insights/post_impressions/lifetime' 

I get syntax error.

I've tried with . notation as:

'[Page ID]/feed.insights/post_impressions/lifetime' 

But stil no luck!

I know I can do it post by post (separate calls to API), but that is what I'm trying to avoid.

Anyone know what the correct syntax is for nested insights?

like image 674
Alejandro Sherwell Avatar asked Aug 12 '16 18:08

Alejandro Sherwell


1 Answers

This bug report was able to shed some light: https://developers.facebook.com/bugs/1755454881375647/

You can use the metric keyword to specify the metrics you want, like so:

/page-id/posts?fields=insights.metric(post_impressions,post_consumptions_unique)

Name the metrics you are interested in there, and separate them with a comma.

Specifying the period (where applicable) seems to work by the same kind of syntax,

/…?fields=insights.metric(…).period(lifetime)

(Although it might not work to request different periods for different metrics in one go.)

like image 138
CBroe Avatar answered Oct 15 '22 23:10

CBroe