You can pull your data from Facebook Ads through the Ads Insights API. The Insights API provides access to analytics and reporting functionality and the way you interact with your data is by requesting reports where you define exactly the data and its granularity that you need. As in the case of Google, Facebook also exposes a very rich set of APIs that you can use for every aspect of your advertising needs, from creating ads programmatically to see how your campaigns perform. In this post we’ll focus only on how to extract data from Facebook Ads, for further information on what else can be performed through the Facebook Ads related APIs, you can check the documentation of the Marketing API.
As with everything in Facebook, Ads and their statistics are part of the Graph API, which you can interact with also using Graph Explorer, and there’s a special Edge that you can use to request ad’s statistics, it’s the insights edge. Insights can be access from the following list of edges:
The response from each contains information belonging to the ad object for which insights are queried.
For example, let’s assume that you would like to extract all stats related to your account. You could do this by executing the following request using CURL:
curl -F 'level=campaign' -F 'fields=' -F 'access_token=<ACCESS_TOKEN>' https://graph.facebook.com/v2.5/<CAMPAIGN_ID>/insights curl -G -d 'access_token=<ACCESS_TOKEN>' https://graph.facebook.com/v2.5/1000002 curl -G -d 'access_token=<ACCESS_TOKEN>' https://graph.facebook.com/v2.5/1000002/insights
Data can be returned in either xls or csv format and when the report is ready based on your request you can access from a URL like the following:
Get real-time streams of your Facebook Ads stats
It’s also possible to create a real-time data infrastructure for fetching data from Facebook Ads and loading them into your data warehouse repository. You can do that by subscribing to real-time updates to receive API updates with webhooks. With the proper infrastructure, you can have an almost real-time feed of data into your repository and ensure that it will always be up to date with the latest data.
Facebook Ads exposes a very rich API which offers you the opportunity to get very granular data about your accounting activities and use it for analytic and reporting purposes. This richness comes with a price though, a large number of complex resources that have to be handled through an also complex protocol.