Search code examples
restfacebook-graph-apifacebook-ads-apifacebook-ads

How to pull ad insights in bulk using Facebook Graph API?


I am trying to do what I thought would be a very simple task which is to use the Facebook API to retrieve insights about ads, but I'm having so much trouble. I know how to use multiple API calls to retrieve the list of ads, and then retrieve the insights for each ads using an API call for each one.

However, I'm limited at 200 API calls per hour, so this is no good if I wanted to pull all ads from all-time. There is a way to batch call the ad insights using an endpoint like:

act_XXXXXXXXXXXXXXX/ads?fields=insights{cpc, impressions}

But then I am unable to specify the timeframe so it only grabs stats from the past month. Usually I would specify the timeframe with a field of

date_preset=maximum

(or whatever I want the date_preset to be), but in this case if I add it as another field it does not affect the the insights (I presume since they are using those brackets as a special way to pull the bulk insights).

I swear to god if I figure this out I'm releasing it publicly and loudly for free because I think it's ridiculous that this is so roundabout.


Solution

  • Do this: act_XXXXXXXXXXXXXXX/ads?fields=insights.date_preset(maximum){cpc, impressions} This is called a nested query.