Python,facebook-python-business-sdk:如何将图形API限制从25增加到500

时间:2019-09-24 09:37:10

标签: python facebook facebook-graph-api facebook-marketing-api facebook-python-business-sdk

我使用以下API:

  https://github.com/facebook/facebook-python-business-sdk

我需要指定限制字段以从Facebook返回更多结果的地方。

我的代码:

fields = [
    AdsInsights.Field.campaign_id,
    AdsInsights.Field.campaign_name,

    AdsInsights.Field.adset_id,
    AdsInsights.Field.adset_name,
    AdsInsights.Field.ad_name,

    AdsInsights.Field.spend,
    AdsInsights.Field.impressions,
    AdsInsights.Field.clicks,
    AdsInsights.Field.account_currency,
]
params = {
    'time_range': {
        'since': for_day,
        'until': for_day
    },
    'fields': fields,
    'breakdowns': ['country'],
    'action_report_time': AdsInsights.ActionReportTime.impression,
    'level': AdsInsights.Level.ad
    # todo: need to find way to query for 500 records
}

async_job = account.get_insights_async(fields=params.get('fields'), params=params)

稍后,当我观看结果对象时,会看到以下内容:

https://graph.facebook.com/v4.0/yyy/insights?access_token=xxx& 限制= 25 &after = zzz

1 个答案:

答案 0 :(得分:0)

只需添加参数,例如:

params = {
    'limit': '500',
    'time_range': {
        'since': for_day,
        'until': for_day
    },
    'fields': fields,
    'breakdowns': ['country'],
    'action_report_time': AdsInsights.ActionReportTime.impression,
    'level': AdsInsights.Level.ad
}

希望获得帮助