6

I am attempting to use the Facebook-Python-Ads-SDK to automate reporting on Ad Account performance. I have successfully requested a report at the ad set level, however the output of the report is a Cursor object, where I would prefer it to be a json or csv. I have tried the "export_format" option in params but it does not seem to make any difference. The output looks like JSON, so I attempted to import the object as a dataframe in pandas using pd.read_json(result) but it gives off an error saying that the object type "Cursor" needs to be str or bytes.

Does anyone have any experience with this api that can help me out? My code is below.

def report_request(start_date,end_date):
    fields = [
        'date_start',
        'account_name',
        'adset_name',
        'ad_name',
        'impressions',
        'clicks',
        'spend'
    ]
    params = {
        'time_range': {
            'since': start_time,
            'until': end_time,
        },
        'level':'ad',
        'export_format':'csv'
    }
    account_id = [<ACCOUNT_ID>]
    adAccount = AdAccount('act_' + account_id)
    api_batch = get_api().new_batch()
    request = adAccount.get_insights(fields=fields, params=params, async=False, batch=api_batch)
    result = request.execute()
    return result
R.Z.
  • 101
  • 6
  • 1
    https://stackoverflow.com/questions/34092054/how-to-parse-nested-fb-api-response-from-python-sdk/36397567. I am also looking for the best way to do this. I found this which works, but it doesn't feel optimal. – Hound Feb 12 '19 at 23:59

0 Answers0