Get data from time range in facebook ads api - facebook

How to get data from the time range 2020-05-06 to 2020-06-06?
This query does not work:
<ACC_ID>/ads?time_range={'since':'2020-05-06','until':'2020-06-06'}&fields=insights{cpc,spend}

I suggest you to use the Insights Marketing API that support filtering, sorting and useful aggregation level, in your case, should be something like:
act_XXX/insights?level=ad&fields=cpc,spend&time_range={'since':'2020-05-06','until':'2020-06-06'}
Other info here

Related

facebook marketing api - results and cost per result

I want to retrieve via API the values for cost per result and results columns of the facebook business manager. Is this possible?
Yes its possible through the Insight API.
Request insights for a campaign and the cost_per_action_type field. The cost_per_action_type field will be an array containing the cost per result of various action types.
In a traffic campaign the action type of interest is link_click. The value for link_clicks is what you would see under results in the fb ad manager.
https://developers.facebook.com/docs/marketing-api/reference/ad-campaign-group/insights/

Kinvey Rest Api Modify return-data of App Call according to the requesting user

To reduce the amount of downloaded data and thus data and CPU usage, I want to remove entities not matching an attribute of the calling user from the data returned, only using the Kinvey REST API.
To clarify my wish, here an example:
User ID=1
Data:
ID=1, Value='a'
ID=3, Value='b'
ID=2, Value='c'
ID=1,Value='d'
ID=2,Value='e'
Now I want to reduce the data to only the entities matching the Users ID, so
Value='a' and Value='d'
Any suggestions would be greatly appreciated. Thanks!
First, please do not use the REST API, but use an appropriate SDK for your development platform. The REST API's handshakes for login, maintaining your token, etc. is all quite hard and the SDK's do the hard for you.
Each SDK has operators for querying. For instance, with Swift, it'll look like this:
http://devcenter.kinvey.com/ios/guides/datastore#operators
KCSQuery(onField: "colors", usingConditional: .KCSAll, forValue: [1])
For completeness, in the REST API this would be modeled with the query parameter, like this:
?query={"ID":1}

Possible to specify date_preset with insights edge in Facebook Ads API?

For the Marketing API, I know that I'm able to make one call to retrieve all of the adsets from a certain account along with their insights, but am I able to specify the date_preset for the insights edge in that same call?
For example, the following gives me lifetime insights stats:
/v2.4/{accountID}/adcampaigns?fields=insights
To be clear - I know this is possible to retrieve by making separate calls for each adset id (where I know I can specify the date_preset); instead, I'd like to do this via the call where I get a long list of the ad sets plus their insights details in one go.
Yes this is possible using query expansion, however you probably should not do it in this anyway.
Using query expansion results in multiple requests being executed in one HTTP call, in this case one to get all the adcampaigns, and then N requests where N is the number of adcampaigns returned. This will in turn affect your rate limiting.
The most efficient way to request all insights for all adcampaigns (ad sets) is instead to request them at the account level, specifying aggregation level:
/v2.4/act_{ADACCOUNT_ID}/insights?date_preset=last_7_days&level=campaign
This requires just 1 request, or the number of requests to retrieve the total number of pages.
If you really want to achieve this with query expansion, you can do the following for example:
/v2.4/act_{ADACCOUNT_ID}/adcampaigns?fields=insights.date_preset(last_30_days).time_increment(all_days)
You can see the parameters to insights that would normally be query parameters of the form param_name=param_value are now in the form of param_name(param_value).
To specify the date_preset , here is the correct format . Its important to use insights as edge to get the date_preset filtering .
/v2.10/act_{ADACCOUNT_ID}/insights?fields=impressions,clicks,ctr,unique_clicks,unique_ctr,spend,cpc&date_preset=last_3d
The above one is tested with latest Graph Api version(2.10) as of now . FOr more info related to the date_preset values refer to there api docs .
https://developers.facebook.com/docs/marketing-api/insights/parameters

Search API Facebook Graph by date range

is there any way to explore the Facebook Graph API by date range? Ex. to find all events on February?
I use following code, but I’m not sure, that’s correct request:
since=2015-01-28T00:00:00%2B0000&until=2015-01-30T00:00:00%2B00000
In this way, I get records for defined date range - ok, but there is missing events – a set is incomplete (despite it doesn’t exceed a limit of API). Why I can’t get all of results for given query?
Maybe do you know another method of filtering results by date?
thanks
There's no way to restrict the search results by since and until as far as I know.
For searching events, you can use the /search endpoint as described at
https://developers.facebook.com/docs/graph-api/using-graph-api/v2.2#search
but I guess there's no further way to filter the results other than specifying the q parameter.

Query multiple insights metrics in one API call

Is it possible to query more than one insights metric in one API call?
For example to get the daily added likes for a page I executed the following call:
https://graph.facebook.com/_object_id_/insights/page_fan_adds_unique/day/
But I would like to have another metric, e.g., page_fan_removes_unique, included as well.
Query the insights object entirely is a possibility, but gives me too much data I don't need, thus decreases performance.
Since your question shows that you're using the Graph API, you may want to use the batch requests method: http://developers.facebook.com/docs/reference/api/batch/
You can group multiple Graph API queries together so you can just query the Insights data you need in one request.
Yes, you can run a multiple FQL query in one API call and then parse the various results.
multi query: http://developers.facebook.com/docs/reference/rest/fql.multiquery/
insights table: http://developers.facebook.com/docs/reference/fql/insights/