Getting Ad Insights from Facebook — and avoiding error 17

Sam Kenny
Sam Kenny
Jan 14, 2016 · 1 min read

At untapt measuring the success of our marketing campaigns across social media is important — to us and our clients. If we are going to put dollars into a campaign to find the best tech talent around the world, we need to know which social media platforms are performing best.

I’ve struggled with the Facebook API so I thought I would do a quick recap of the solution I implemented in Python. In doing so, I had to make sure that the number of API calls was limited so avoid Error 17 — user request limit reached.

The most important discovery in the code below was that insights can be retrieved for the account, but to see them aggregated at the ad level you simply need to pass the ‘level’ parameter.

from facebookads.api import FacebookAdsApi
from facebookads.objects import AdAccount, AdCreative, AdPreview, AdCreativePreview, Ad, Insights

Sam Kenny’s a(musing)

Random tech articles and tidbits of interest

Sam Kenny

Written by

Sam Kenny

engineer @ untapt

Sam Kenny’s a(musing)

Random tech articles and tidbits of interest