Skip to content

Instantly share code, notes, and snippets.

@mafellows
Created June 25, 2020 16:03
Show Gist options
  • Save mafellows/2e519bb8e312f8bfe4499d5d43f02ef0 to your computer and use it in GitHub Desktop.
Save mafellows/2e519bb8e312f8bfe4499d5d43f02ef0 to your computer and use it in GitHub Desktop.
import json
import decimal
import os
import datetime
from facebook_business.adobjects.adaccount import AdAccount
from facebook_business.adobjects.adsinsights import AdsInsights
from facebook_business.api import FacebookAdsApi
account_uuid = '1d171536-e162-436c-8c47-1ff54456a3e4'
response = table.query(
KeyConditionExpression=Key('pk').eq('account') & Key('sk').eq(account_uuid)
)
account = response['Items'][0]
access_token = '__token__'
ad_account_id = 'act_' + '__account_id__'
app_secret = '__secret__'
app_id = '__app_id__'
FacebookAdsApi.init(access_token=access_token)
fields = [
'spend',
'purchase_roas'
]
params = {
'level': 'account',
'filtering': [{'field':'updated_time','operator':'GREATER_THAN','value':1590296400000}],
'breakdowns': ['ad_id'],
'time_range': {"since":"2020-04-28","until":"2020-05-28"}
}
insights = AdAccount(ad_account_id).get_insights(
fields=fields,
params=params,
)
print(insights) # Returns empty array []
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment