0

i am trying to use python request for accessing facebook ads daily total spend. I tried this solution but i don't have app_secret so i try this but this one focus on campaign level spends.

My question is how i can get daily total spend with request or how can i use facebook python sdk with only account id and access token as used in example in the link and get only date and total spend? Below code shows ad level for me but i can't groupby date to sum spend because date column here is interval . b

import requests
import json
token='*****'
act_id='act_*******'
first_request = 'https://graph.facebook.com/v7.0/act_id/campaigns?fields=insights{spend}&limit=10000&access_token=%s'%token
result = requests.get(first_request)
content_dict = json.loads(result.content)
content_dict

this is a sample the output example:

 {'insights': {'data': [{'spend': '31.39',
          'date_start': '2020-04-13',
          'date_stop': '2020-05-12'}],
        'paging': {'cursors': {'before': 'MAZDZD', 'after': 'MAZDZD'}}},
   'id': '*******'},
Umar
  • 1

1 Answers1

0

To get the spend of an ad account, you can query the insights on the ad account level.

GET: /act_id/insights?level=account&time_range={"since":"2015-01-01","until":"2020-06-05"}&fields=spend

Note: If you replace level by campaign it will give you spend by campaign

For more details, please check the official doc

Rachid
  • 206
  • 1
  • 3