Answer the question
In order to leave comments, you need to log in
Facebook Python API: how to get user's location name?
Hello! How to get user's location name in ad statistics?
I have the following function so far:
def parse_ads_stat(account_id, data):
print('printing data')
print(f'data: {data}')
stat = dict()
stat['fb_ad_account'] = [account_id for i in range(len(data))]
stat['fb_campaign_id'] = [data[i]['campaign_id'] for i in range(len(data))]
stat['fb_adset_id'] = [data[i]['adset_id'] for i in range(len(data))]
stat['fb_ad_id'] = [data[i]['ad_id'] for i in range(len(data))]
stat['fb_spend'] = [str(data[i]['spend']).replace('.', ',') for i in range(len(data))]
stat['fb_date'] = [data[i]['date_start'] for i in range(len(data))]
stat['impressions'] = [data[i]['impressions'] for i in range(len(data))]
stat['clicks'] = [data[i]['clicks'] for i in range(len(data))]
stat['reach'] = [data[i]['reach'] for i in range(len(data))]
stat['location'] = [d.get('location', [{}])[0].get('value', 0) for d in data]
stat['video_p25_watched_actions'] = [d.get('video_p25_watched_actions', [{}])[0].get('value', 0) for d in data]
stat['video_p50_watched_actions'] = [d.get('video_p50_watched_actions', [{}])[0].get('value', 0) for d in data]
stat['video_p75_watched_actions'] = [d.get('video_p75_watched_actions', [{}])[0].get('value', 0) for d in data]
stat['video_p100_watched_actions'] = [d.get('video_p100_watched_actions', [{}])[0].get('value', 0) for d in data]
stat['video_play_actions'] = [d.get('video_play_actions', [{}])[0].get('value', 0) for d in data]
return stat
{'ad_id': '23847664832490708', 'campaign_id': '23847664832280708', 'adset_id': '23847664832290708', 'spend': '314.6', 'impressions': '1878', 'clicks': '22', 'reach': '1865', 'date_start': '2021-04-15', 'date_stop': '2021-04-15'}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question