I wrote this script that returns a list of ads with their stats but apprently I’m getting only insights for active ads and not paused ones – For paused ones, I’m just getting the campaign name and its id !
I tried using filtering like below but it’s not working:
”
first = "https://graph.facebook.com/v3.2/act_105433210/campaigns?filtering=[{'field':'effective_status','operator':'IN','value':['PAUSED']}]&fields=created_time,name,effective_status,insights{spend,impressions,clicks}&access_token=%s"% token
Then I check using:
result = requests.get(first)
content_dict = json.loads(result.content)
print(content_dict)
and this is a sample of the output I get:
{'data': [{'created_time': '2019-02-15T17:24:29+0100', 'name': '20122301-FB-BOOST-EVENT-CC SDSDSD', 'effective_status': 'PAUSED', 'id': '6118169436761'}
There is only the name of the campaign and not insights !
Anyone did retrieve stats/insights for paused ads/campaigns before or not?
Thanks !
Please check my other post of my python script : I can't fetch stats for all my facebook campaigns using Python and Facebook Marketing API
2
Answers
After days of digging around, I finally come up with a script that I did run to extract 3 years of facebook ads insights avoiding the rate limit of the facebook API.
First, we import the lib we'll need :
Please note that after extracting the insights, I'm saving them on Google Cloud storage then on Big Query tables.
Then, the following scripts calls the api and check the rate limit we did reach:
Now, this is the whole script that you can run to extract data of the last X days !
This did perfectly works but note that if you're planning to extract 3 years of data, the script will take a lot of time to run !
I'd like to thank LucyTurtle and Ashish Baid for their scripts that did help me during my work!
Please refer to this post if you need more details or if you need to extract data for one day for different ad accounts :
You could combine more filtering criteria as example, for filter paused campaign, that the name contain the string
name
and start from the 1 march you can use:the timestamp should be an epoch timestamp, in the example is the: