7

I'm trying to obtain impressions of my ads between two dates

I'm using Graph API Explorer with this path:

act_0123456789/ads?fields=insights{ad_id,ad_name,impressions}

I want to use 'time_range' attribute that we can find it in Marketing API reference but I don't know the syntax. Anyone can help me?

ffflabs
  • 15,728
  • 5
  • 48
  • 71
David
  • 405
  • 2
  • 6
  • 18

3 Answers3

20

I can't comment on the approach you're using as I have not used it myself. However, here is an alternative approach which I have used with success:

https://graph.facebook.com/v2.5/act_xyz/insights?level=<yourLevel>&fields=ad_id,ad_name,impressions&time_range[since]=2016-02-15&time_range[until]=2016-02-16&limit=25

where <yourLevel> can be one of: ad, adset, campaign

Also note that I am using straight up http requests in java which is why I show you the request itself. Hopefully you can extrapolate to your own solution.

Mr Lister
  • 42,557
  • 14
  • 95
  • 136
Al Ducent
  • 248
  • 2
  • 6
9

Using the same endpoint you've shown in your question

act_0123456789/ads?fields=insights{ad_id,ad_name,impressions}

The way to specify a time range would be

act_0123456789/ads?fields=insights.time_range({"since":"2017-08-07","until":"2017-08-14"}){ad_id,ad_name,impressions}

(of course, those two dates are provided just as an example)

ffflabs
  • 15,728
  • 5
  • 48
  • 71
  • 1
    Caveat: this answer was made when FB Api was in v2.4, I don't know if this still works for v3.3+ and I no longer use this API nor do I have access to any Page/Business to try it – ffflabs Aug 15 '19 at 16:56
3

Easiest way of doing this is

act_0123456789?fields=ads{insights.time_range({"since":"2019-03-03","until":"2019-03-03"}).time_increment(1){impressions}}

Remove .time_increment(1) if you don't want day by day data

you can use {} for subfields like

 act_0123456789?fields=campaigns{ads{name,insights,adcreatives{image_url}}}

you can use . and () for parameters like; always make sure you use you use fields only after parameters like this order .(){}

act_0123456789?fields=campaigns.limit(1).time_range({"since":"2019-03-03","until":"2019-03-03"}).time_increment(1).breakdowns(country){ads{name,insights.time_range({"since":"2019-03-03","until":"2019-03-03"}).time_increment(1).breakdowns(country),adcreatives{image_url}}}
MUHAMMED IQBAL
  • 127
  • 1
  • 1
  • 5