Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to combine Graph API field expansions?

When using this syntax to query multiple metrics

https://graph.facebook.com/v2.4/69999732748?fields=insights.metric(page_fan_adds_unique,page_fan_adds,page_fan_adds_by_paid_non_paid_unique)&access_token=XYZ&period=day&since=2015-08-12&until=2015-08-13

I always get data for the last three days regardness of the values of the since and until parameters

https://graph.facebook.com/v2.4/69999732748/insights/page_fan_adds_unique?period=day&access_token=XYZ&since=2015-09-10&until=2015-09-11

If I ask for a single metric, then the date parameters have effect.

Is there a different syntax for requesting multiple insights metrics which will accept the date parameters?

like image 395
Chris Harrington Avatar asked Sep 16 '15 00:09

Chris Harrington


1 Answers

I think this should work:

curl -G \
-d "access_token=PAGE_TOKEN" \
-d "fields=insights.metric(page_fan_adds_unique,page_fan_adds,page_fan_adds_by_paid_non_paid_unique).since(2015-08-12).until(2015-08-13).period(day)" \
-d "pretty=1" \
"https://graph.facebook.com/v2.4/me"

You are requesting the page's insights as a field. This field contains a list of results in a data array (insights.data), and you want to filter this array.

The way to do that is by chaining parameterizations to the requested insights field like so:

fields=insights
  .filter1(params)
  .filter2(params)
  .filter3(params)

Each .filterX(params) will be applied to the particular field that precedes it.
I've added newlines and indentation for clarity, but in your actual request you'd chain them all in a single line, without spaces.

like image 162
derabbink Avatar answered Sep 21 '22 19:09

derabbink