How can I get more than 25 results from Facebook's insights api using Facebook-business-python-sdk?
Digital Marketing
Facebook Marketing API
2 years ago
5
Star Rating
1
Rating
_x000D_
_x000D_
I'm trying to get basic ad level data from Facebook's insights API using facebook-python-business-sdk with python 3.7.
The problem is I'm only getting 25 results back, even in accounts that have more than 25 active ads.
I'm using the get_insights method on each account, passing a 'level':'ad' param and filtering on a specific date.
I've also checked whether I've reached facebook's limit (using the explanation provided here) and I'm not even close to the limit.
The get_insights method doesn't have a 'limit' param and either way I don't want to limit it at all as some accounts may have hundreds or even thousands of ads.
This is the code I'm using
from facebook_business.api import FacebookAdsApi
from facebook_business.adobjects.adaccount import AdAccount
from facebook_business.adobjects.adaccountuser import AdAccountUser
from facebook_business.adobjects.campaign import Campaign as AdCampaign
from facebook_business.adobjects.adsinsights import AdsInsights
access_token = '******'
app_secret = '******'
app_id = '******'
FacebookAdsApi.init(app_id, app_secret, access_token)
me = AdAccountUser(fbid='me')
my_accounts = list(me.get_ad_accounts())
params={'time_range': {'since': '2019-06-29', 'until': '2019-06-29'},'level': 'ad'}
fields = [AdsInsights.Field.account_id,
AdsInsights.Field.account_name,
AdsInsights.Field.ad_id,
AdsInsights.Field.ad_name,
AdsInsights.Field.adset_id,
AdsInsights.Field.adset_name,
AdsInsights.Field.campaign_id,
AdsInsights.Field.campaign_name,
AdsInsights.Field.spend,
AdsInsights.Field.impressions,
AdsInsights.Field.clicks,
AdsInsights.Field.outbound_clicks,
]
for account in my_accounts:
ads = account.get_insights(params=params, fields=fields)
print(ads)
print(len(ads))
I expected to get all ads in each account but I'm only getting a maximum of 25 ads per account.
Any help will be greatly appreciated!
Thanks
Posted on 16 Aug 2022, this text provides information on Facebook Marketing API related to Digital Marketing. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.
Take Quiz To Earn Credits!
Turn Your Knowledge into Earnings.