I would like to get insights of all my active campaigns running on Facebook Ads. I manage to get all campaigns with FacebookAdsApi on my account but i am not able to use a filter so i only get campaigns with the "ACTIVE" status.
Here is my code so far:
from facebookads.api import FacebookAdsApi
from facebookads.objects import AdAccount, Ad, Insights, AdUser
import datetime
my_app_id = 'xxx'
my_app_secret = 'xxx'
my_access_token = 'xxx'
FacebookAdsApi.init(my_app_id, my_app_secret, my_access_token)
me = AdUser(fbid='me')
my_accounts = list(me.get_ad_accounts())
my_account = my_accounts[0]
fields = [
Insights.Field.campaign_name,
Insights.Field.spend
]
params = {
'time_range': {'since': str(datetime.date(2015, 1, 1)), 'until': str(datetime.date.today())},
'level': 'campaign',
'limit': 1000
}
insights = my_account.get_insights(fields=fields, params=params)
print len(insights)
>>> 115
I tried to add the following line to params
:
filtering': [{'field': 'campaign.effective_status','operator':'IN','value':['ACTIVE']}]
which results in this error-msg:
"error_user_msg": "The reporting data you are trying to fetch has too many rows. Please use asynchronous query or restrict amount of ad IDs or time ranges to fetch the data."
I can get all campaigns from my account (115) without any issue and there are only 10 active campaigns at the moment so i guess my filter is wrong?