Use time range in the Ad Insights Facebook Marketing API

I am trying to get impressions of my ads between two dates

I am using the Graph API Explorer with this path:

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

I want to use the time_range attribute, which we can find in the API Marketing Reference , but I don’t know the syntax. Can anybody help me?

+6
source share
3 answers

I cannot comment on the approach you are using, as I have not used it myself. However, here is an alternative approach that 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'm using direct http requests in java, so I am showing you the request itself. Hope you can extrapolate your solution.

+14
source

Using the same endpoint that you indicated 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, these two dates are given as an example)

+6
source

The easiest way to do it

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

Delete .time_increment (1) if you don't want day-to-day data

You can use {} for subfields such as

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

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

 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}}} 
0
source

Source: https://habr.com/ru/post/1243080/


All Articles