Get results for specific facebook marketing campaigns objectives - facebook

Each Facebook ad campaign has an objective, such as LINK_CLICKS or CONVERSIONS.
In Ad Manager, one can see the performance of each of their ad campaigns. There is a column called "results" that has the number of objective-specific conversions for that campaign. So for example, if the objective is PAGE_LIKES then results would show the number of page likes resulting from the campaign, but if the objective was LINK_CLICKS then results would show website clicks.
My question is: Is there something in the Insights API that equates to the results column in Ad Manager? Part of the reason I ask is for ease and consistency, but also some of the objectives are ambiguous, e.g. BRAND_AWARENESS.

No, I haven't been able to easily replicate the results and cost per result columns from the ad manager with an API call.
First you can check the URL when in the ad manager to see which columns are selected by looking at the GET parameter columns:
https://business.facebook.com/ads/manage/powereditor/manage/ads?act=...&business_id=..&columns=name%2Cerrors%2Cdelivery%2Cresults%2Creach%2Cimpressions%2Ccost_per_result&...
Decoding this gives the following fields:
columns=name,errors,delivery,results,reach,impressions,cost_per_result
Now it looks like we could simply use the result and cost_per_result fields, but that gives an error:
(#100) results, cost_per_result are not valid for fields param.
This is expected as the API document doesn't specify results and cost_per_result as valid fields.
Now when in the ad manager we can also see the API calls use the network tab of developer tools to see it making API calls to retrieve data. This shows us the result and cost_per_result fields being used. You can actually copy the request URl and see it working... somehow..
Trying to recreate this API call in the Graph API Explorer only worked for me when I copied the access token from the previous call. This makes me feel that the business manager has a special access token.

Related

How to pull ad insights in bulk using Facebook Graph API?

I am trying to do what I thought would be a very simple task which is to use the Facebook API to retrieve insights about ads, but I'm having so much trouble. I know how to use multiple API calls to retrieve the list of ads, and then retrieve the insights for each ads using an API call for each one.
However, I'm limited at 200 API calls per hour, so this is no good if I wanted to pull all ads from all-time. There is a way to batch call the ad insights using an endpoint like:
act_XXXXXXXXXXXXXXX/ads?fields=insights{cpc, impressions}
But then I am unable to specify the timeframe so it only grabs stats from the past month. Usually I would specify the timeframe with a field of
date_preset=maximum
(or whatever I want the date_preset to be), but in this case if I add it as another field it does not affect the the insights (I presume since they are using those brackets as a special way to pull the bulk insights).
I swear to god if I figure this out I'm releasing it publicly and loudly for free because I think it's ridiculous that this is so roundabout.
Do this: act_XXXXXXXXXXXXXXX/ads?fields=insights.date_preset(maximum){cpc, impressions} This is called a nested query.

Facebook marketing API Does not select the correct pixel conversion event

I'v built an app that creates ads using the marketing API. When it creates the adset it sets a specific pixel and a page view event.
All our users get the correct pixel and the correct event except for one user.
Here is the object from the post request that is being sent to Facebook where we can see that they are equal
User one
"promoted_object":"{\"pixel_id\":xxxxxxxxxx63,\"custom_event_type\":\"CONTENT_VIEW\",\"pixel_rule\":\"{\\\"event\\\":{\\\"eq\\\":\\\"PageView\\\"}}\"
User two
"promoted_object":"{\"pixel_id\":xxxxxxxxxx63,\"custom_event_type\":\"CONTENT_VIEW\",\"pixel_rule\":\"{\\\"event\\\":{\\\"eq\\\":\\\"PageView\\\"}}\"
Both get the correct pixel with the correct id but one gets no conversion event, and say Missing conversion event.
Both ad accounts have full access to the pixel under the business settings in ads manager.
Here is an image that describes the issue.
Anyone have any ideas here?
make sure the conversion event is defined in that account.
The conversion event is usually set on Campaign Level and supplied when you create a campaign via API.
As you're trying to use a custom conversion it might be that you've created it for one account but didn't create it for another. That's why you don't see it in you campaign setup view. You can create it via API as described here:
Custom Conversion API
Or just do it via Business Manager and use it afterward when creating you campaigns via API or manually.
It's definitely not a request that fails in this case but a proper account configuration.

Cannot retrieve the reach estimate for some Facebook ads (from the API)

The API lacks some clear explanations on retrieving the reachestimate for either an ad account or an ad. I have made sure that:
I am an admin/ or added to a Facebook app
I have a paid advertising campaign
The adaccount ID is added in the Settings Advanced panel of the Developer App page
I've been trying to:
In Graph API Explorer, retrieve the data by query expansion: me?fields=adaccounts{campaigns{adsets{ads{reachestimate}}}}. However, I always get one of the following (randomly):
Still in the explorer, retrieve it by direct access: act_{adaccount_id}/reachestimate I get this, even if I am 100% sure the ad account is added in the Advanced Settings panel:
Both of 1 and 2 in the iOS project. I get this: com.facebook.sdk.core error 8
Test it by curl with the example from here. I get this (the same with the one from point 2): The ad account is not enabled for usage in Ads API.
Just as a further note, for point 1 that's not the whole query, but I didn't write the adjacent fields because they would've been redundant for the purpose of this question.
I simply need to retrieve the ad accounts, the campaigns, the ad sets and the reach estimate simultaneously in the same query. It seems like a dead spot for me. Do you have any suggestions? Can you show me a Graph API explorer working example? Or, if what I'm asking is impossible, can you simply show some code that works?
Are you app and ad account owned by the same person?
Facebook Ads API has tiered access. https://developers.facebook.com/docs/marketing-api/access
A newly registered app is in Development Tier and can only access the user's own ad accounts. You need to make some API calls on your own ad account for testing in order to get promoted to Basic Tier and manage other people's ad account.
Apparently, I got:
Please reduce the amount of data you're asking for, then retry your request.
Because the query was to broad. Those 'adjacent' fields actually triggered a massive query, so the solution was to either:
Put a limit(1) on the campaigns.
Individually retrieve the reachestimate for each adset.
I chose the latter because it suited my needs, but it's up to you which solution works better.

How to retrieve multiple user account details through their Facebook IDs in graph API?

This could be a duplicate of here and here, but can some one provide a complete working example for following.
I have set of different Facebook account Ids, and i need to get the respective account details(user name etc) from these account ids. I need to send a Batch Request for Graph API. Something as follows,
(https://graph.facebook.com?ids=user1, user2, user3,...)
Is this possible as pure HTTP GET request ?
I am using Facebook SDK with Android for the moment. I have gone through the API doc but unable to build the required query yet. Please help.
Maybe post a snippet of your code so we can try to solve your problem better. With the info you provided, the URL https://graph.facebook.com/?ids=user1,user2,user3 works just fine and returns 3 users.
The URL format looks correct. Keep in mind the total character limit, but otherwise I suspect you are stuck in a different place (e.g. sending the query or saving the result).

Is it bad practice for a REST endpoint to return different response fields based on the request?

I'm developing a 'user' endpoint for my mobile app. When the authenticated user GETs another user's profile, I want to return fewer fields than when they GET their own.
Is it semantically bad/against REST principles to return a different set of fields from a REST endpoint depending on some criteria such as whether the requesting user is retrieving their data vs another user's, or should I just have 2 endpoints for the same data source?
It's totally fine to return differing sets of data for the same URL based on authentication criteria. Think about a plain old web site. If you're logged in, you usually see diff contextual information than you do if you're anonymous, right? So getting more info back in the content of your response when it's the "current" user vs. a diff user is the same thing. If you really wanted to separate the fields you could with a sub-URL, but you definitely don't have to.