By Rudderstack Team

How to load data from the Facebook Ads to Snowflake

This post helps you with loading your data from Facebook Ads to Snowflake. If you are looking to get analytics-ready data without the manual hassle you can integrate Facebook Ads to Snowflake with RudderStack, so you can focus on what matters, getting value out of your advertising data.

Extract data from Facebook Ads

You can pull your data out of Facebook Ads through the Ads Insights API. The Insights API provides access to analytics and reporting functionality and the way you interact with 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 advertisement needs, from creating ads programmatically to see how your campaigns perform.

In this post we’ll focus only on how to extract Facebook Ads data, for further information on what else can be performed through the Facebook Ads-related APIs, you can check the documentation of the Marketing API.

Before you start doing anything, have a read on how to activate and manage your developer account. And make sure that you understand the security-related concepts of the Facebook Marketing API. In general, access to the API happens mainly through the SDKs that Facebook offers. Officially, SDKs for PHP and Python are supported, while there are also a number of community-supported SDKs for languages like R, JavaScript, and Ruby.

You can also find more if you do some research on places like GitHub. The Facebook Marketing API is a RESTful web API and thus can also be accessed by performing requests directly to the appropriate endpoints. As a RESTful API, interacting with it can be achieved by using tools like CURL or Postman or by using HTTP clients for your favorite language or framework. A few suggestions:

  • Apache HttpClient for Java
  • Spray-client for Scala
  • Hyper for Rust
  • Ruby rest-client
  • Python http-client

As with everything in Facebook, Ads and their statistics are part of the Graph API, which you can interact with also using the 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:

https://www.facebook.com/ads/ads_insights/export_report?report_run_id=<REPORT_ID>&format=<REPORT_FORMAT