通过分页从FB ads API检索异步广告见解结果 [英] retrieve async ads insights results from FB ads API with pagination

查看:61
本文介绍了通过分页从FB ads API检索异步广告见解结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 facebook-python- ads-sdk 描述了.

params = {
    "time_increment": 1,
    "level": "ad",
    "date_preset": "last_28d",
    "breakdowns": "hourly_stats_aggregated_by_advertiser_time_zone",
    "limit": 1000
}

job = AdAccount("id").get_insights_async(params=params)
result_cursor = wait_for_async_job(job)
results = [item for item in result_cursor]

def wait_for_async_job(job):
    for _ in range(TIMEOUT):
        time.sleep(1)
        job = job.remote_read()
        status = job[AdReportRun.Field.async_status]
        if status == "Job Completed":
            return job.get_result()

因此,检索last_28d的见解的工作在几分钟内完成,但是,对结果进行分页可能需要一个小时!

So the job to retrieve insights for last_28d finishes in a few minutes, however, the pagination over the results can take up to an hour!

对异步作业进行分页是否正确?

Is it the right way to paginate over an async job?

推荐答案

我正在发布答案,以便它可以帮助遇到相同问题的其他开发人员.

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

修改:

return job.get_result()

收件人:

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

这将对结果进行分页,跳转数为1000,而不是默认值25.

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

以上更改为我们节省了30分钟的运行时间.

The above change saved us 30 minutes of run.

这篇关于通过分页从FB ads API检索异步广告见解结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆