-1

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. 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?

2 Answers2

1

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.

Zahid Sattar
  • 1,467
  • 2
  • 13
  • 21
1

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?

Josef
  • 2,869
  • 2
  • 22
  • 23