facebook / facebook-python-business-sdk

Python SDK for Meta Marketing APIs
https://developers.facebook.com/docs/business-sdk
Other
1.29k stars 636 forks source link

Limit columns in csv export #432

Closed Knifven closed 6 years ago

Knifven commented 6 years ago

Hi,

I am making a call like

params = {
        'level': AdsInsights.Level.ad,
        'breakdowns': ['publisher_platform'],
        'time_range': {
            'since': start_date,
            'until': end_date,
        },
        'action_attribution_windows': ['28d_click','1d_view'],
        'time_increment': 1,
        'fields': [
            AdsInsights.Field.account_name,
            AdsInsights.Field.campaign_name,
            AdsInsights.Field.campaign_id,
            AdsInsights.Field.adset_name,
            AdsInsights.Field.adset_id,
            AdsInsights.Field.ad_name,
            AdsInsights.Field.ad_id,
            AdsInsights.Field.impressions,
            AdsInsights.Field.reach,
            AdsInsights.Field.clicks,
            AdsInsights.Field.spend,
            AdsInsights.Field.actions,
        ],
        'export_columns': ['campaign_name', 'impressions'], #limited number of columns for test purposes
        'export_format': 'csv'
    }
account = AdAccount('act_' + account_id)
async_job = account.get_insights(params=params, async=True)
async_job.remote_read()

I am then making a get request to https://www.facebook.com/ads/ads_insights/export_report/ using the report_run_id from the initial call (making sure it was completed) and passing the access_token and format again. However the file I am returned contains all 400+ columns even though I tried specifying them earlier. I want the csv format over the Cursor returned from async_job.get_result() because the format better suits my purposes.

What should I do to limit the columns returned from the get request?

ksteslicki commented 6 years ago

Hi @Knifven not sure if you are still having this issue, but I noticed that removing "actions" from the fields resulting in the proper columns being exported via: https://www.facebook.com/ads/ads_insights/export_report/.

When viewing the result from the api I noticed that "actions" was an array rather than a string, so if removing actions doesn't work you may want to examine the result via the api and see if there are any other non string fields and remove them.

codytwinton commented 6 years ago

It seems like this issue has been open for more than a few months now. We have made many changes in the SDK since then, including releasing a new version. If you can repro your specific issue with the latest version of the SDK, please create a new issue or comment here with further details.