Skip to content Skip to sidebar Skip to footer

Retrieve Async Ads Insights Results From FB Ads API With Pagination

I am using facebook-python-ads-sdk to make async calls for FB insights API as described. params = { 'time_increment': 1, 'level': 'ad', 'date_preset': 'last_28d', '

Solution 1:

I am posting the answer so it can help other developers that had the same issue.

modify:

return job.get_result()

to:

return job.get_result(params={"limit": 1000})

This will paginate over the results in jumps of 1000 and not the default which is 25.

The above change saved us 30 minutes of run.


Solution 2:

Today I had the same problem and this code works for me

from facebook_business.adobjects.campaign import Campaign
from facebook_business.adobjects.adreportrun import AdReportRun
from facebook_business.adobjects.adsinsights import AdsInsights
import time

campaign = Campaign(<CAMPAIGN_ID>)

params = {
    'level': AdsInsights.Level.campaign,
}
async_job = campaign.get_insights(params=params, is_async=True)
async_job.api_get()
while while async_job[AdReportRun.Field.async_status]!= 'Job Completed':
     time.sleep(1)
     async_job.api_get()
time.sleep(1)
print(async_job.get_result())

Solution 3:

replace

return job.get_result(params={"limit": 1000})

with

list(async_job.get_result())

to get always all responses. get_result() is an iterator.


Post a Comment for "Retrieve Async Ads Insights Results From FB Ads API With Pagination"