简体   繁体   English

从 AdsInsights on Python Facebook SDK 获取所有字段

[英]Get all fields from AdsInsights on Python Facebook SDK

I'm using Facebook's Python SDK to extract Ads Insights, but I can't find the right way to retrieve ALL fields without having to declare them, which is pretty cumbersome.我正在使用 Facebook 的 Python SDK 来提取 Ads Insights,但是我找不到正确的方法来检索所有字段而不必声明它们,这非常麻烦。 My current code looks like this:我当前的代码如下所示:

ads = tempaccount.get_insights(
    params={'date_preset': 'yesterday',
            '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.cost_per_outbound_click,
            AdsInsights.Field.outbound_clicks,
            AdsInsights.Field.spend])

Is there a way to force the "fields" attribute to bring all possible fields without declaring them?有没有办法强制“字段”属性带来所有可能的字段而不声明它们?

Unfortunately, you will need to specify all the required fields.不幸的是,您需要指定所有必填字段。 It's not possible to get all fields without explicitly specifying them.如果不明确指定,就不可能获取所有字段。

My code also looks similar to yours when querying the insights endpoint.在查询见解端点时,我的代码也与您的代码相似。

This worked for me:这对我有用:

from facebookads.adobjects.adsinsights import AdsInsights

for property, value in vars(AdsInsights.Field).items():
    print(property, ":", value)

Got from this post: How to enumerate an object's properties in Python?来自这篇文章: 如何在 Python 中枚举对象的属性?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM