Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use time range in Ad Insights of Facebook Marketing API

I'm trying to obtain impressions of my ads between two dates

I'm using Graph API Explorer with this path:

act_0123456789/ads?fields=insights{ad_id,ad_name,impressions}

I want to use 'time_range' attribute that we can find it in Marketing API reference but I don't know the syntax. Anyone can help me?

like image 438
David Avatar asked Feb 15 '16 19:02

David


People also ask

How do I get Facebook Page Insights on graph API?

You can access Page Insights by typing /insights after the name of your page in the URL field. This command will retrieve all of the Insights associated with your Page. Type "/insights" after your company name. Click the Submit button.

What are the parameters of Facebook analytics?

You can choose up to three individual parameters like a channel, age, or a traffic source. First, you need to choose an event from which you want to see a data breakdown. And then select the relevant parameters you desire. Using breakdowns, you can more easily understand the relationship between users and events.

What can you do with Facebook Marketing API?

What can the Facebook Marketing API do? The Marketing API is an HTTP-based API that you can use to query data, create and manage ads, and perform a wide variety of other tasks. The Marketing API can programmatically access Facebook's advertising platform and optimize your business operations.


2 Answers

I can't comment on the approach you're using as I have not used it myself. However, here is an alternative approach which I have used with success:

https://graph.facebook.com/v2.5/act_xyz/insights?level=<yourLevel>&fields=ad_id,ad_name,impressions&time_range[since]=2016-02-15&time_range[until]=2016-02-16&limit=25

where <yourLevel> can be one of: ad, adset, campaign

Also note that I am using straight up http requests in java which is why I show you the request itself. Hopefully you can extrapolate to your own solution.

like image 107
Al Ducent Avatar answered Sep 29 '22 23:09

Al Ducent


Using the same endpoint you've shown in your question

act_0123456789/ads?fields=insights{ad_id,ad_name,impressions}

The way to specify a time range would be

act_0123456789/ads?fields=insights.time_range({"since":"2017-08-07","until":"2017-08-14"}){ad_id,ad_name,impressions}

(of course, those two dates are provided just as an example)

like image 30
ffflabs Avatar answered Sep 29 '22 22:09

ffflabs