Following the doc here
https://developers.facebook.com/docs/marketing-api/reference/ad-campaign-group/insights/
I'm querying insights on ad performance etc. However, I can't make the time_frame work. A query like this
https://graph.facebook.com/v2.5/_CAMPAIGN_ID_/insights?access_token=AT&time_range&since=2015-11-08&until=2015-11-12
just returns lifetime stats. I've tried to modify the query in many ways, but it's always an error or lifetime.
Any help would be highly appreciated!
Thanks
I imagine you've found the answer by now but this could help someone else as from experience the documentation isn't always the most friendly to jump into.
You'll need to format it as a time_range object, the example object below is from that page of the documentation you included. It's essentially just an object with 2 properties- since and until.
{'since'=>YYYY-MM-DD,'until'=>YYYY-MM-DD}
So from the example URL you're using, rather than setting the since and until values using individual parameters, the time range would be set like this (I've URL encoded the object):
time_range=%7B%22since%22%3A%22YYYY-MM-DD%22%2C%22until%22%3A%22YYYY-MM-DD%22%7D
Another alternative is to pass the time_range
object as below if you don't want to encode the URL
and want to keep the URL clean.
Facebook is smart enough to parse the URL and set the correct time_range
.
https://httpbin.org/get?time_range[since]=2019-08-10&time_range[until]=2019-09-09
If you are doing this in the Graph API Explorer, it should be like below:
I get #2 syntax from Facebook's document itself :|
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With