skip to Main Content

I am using async method to generate the insights report. In order to get data from it, I am iterating over the results where it gives me 25 values at a time. How can I increase this limit?

More details:

Logs:

2017-03-30 09:27:41.926362  DEBUG   171:0   facebook.py:get_ads_insight     insights type: <class 'facebookads.api.Cursor'>
2017-03-30 09:27:41.926979  DEBUG   176:0   facebook.py:get_ads_insight     insights present: 25

Insights API facebook: https://developers.facebook.com/docs/marketing-api/insights/async/v2.8

Sample code:

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

campaign = Campaign(<CAMPAIGN_ID>)
params = {
    'level': AdsInsights.Level.campaign,
}
async_job = campaign.get_insights(params=params, async=True)

async_job.remote_read()

while async_job[AdReportRun.Field.async_percent_completion] < 100:
    time.sleep(1)
    async_job.remote_read()

time.sleep(1)

print(async_job.get_result())

2

Answers


  1. You can pass parameters to get_result(), for example:

    async_job.get_result(params={'limit': '100',})

    Login or Signup to reply.
  2. Add another entry for limit into your params-dict (with declaring limit = 0 or so before):

    params = {
        'limit': limit if limit > 0 else None,
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search