How to further filter Facebook Graph API query on Graph API Explorer for my ad account? - facebook

I'm trying to get the ad spend and mobile app installs for my app using the Facebook Graph API v2.11 for marketing. In the Graph API Explorer, when I try
/act_<my account>/campaigns?fields=insights{actions,spend}&time_range={'since':'2017-07-07','until':'2017-12-12'}
In the output, under "insights", I get an object of this type:
"data": [
{
"actions": [
{
"action_type": "comment",
"value": "3"
},
{
"action_type": "like",
"value": "33"
},
{
"action_type": "link_click",
"value": "1531"
},
{
"action_type": "mobile_app_install",
"value": "1049"
}
],
"spend": "8621.03",
"date_start": "2017-10-28",
"date_stop": "2017-11-26"
}
]
If I want it to fetch only the actions where action type is "mobile_app_install", how can I further filter my query?

There is possible to filter that on Facebook side just call it like that:
/act_<yourAdAccount>/insights
?level=campaign
&fields=actions,spend
&time_increment=all_days
&time_range={'since':'2017-07-07','until':'2017-12-12'}
&filtering=[{field: "action_type",operator:"IN", value: ['mobile_app_install']}]
&use_account_attribution_setting=true

I have gone through the documentation as well as the adsinsights.py file on github but I cannot find a way to limit the number of action_types returned. You will simply have to do the filtering after you have retrieved the data from the api.
https://developers.facebook.com/docs/marketing-api/insights/parameters
https://github.com/facebook/facebook-python-ads-sdk/blob/master/facebookads/adobjects/adsinsights.py

Related

Retrieve impressions of a post that was made via my Facebook App

There is a way to get the impressions insights of a post throught the graph api? I use my app to publish photos in the users profiles with then permission but i dont get any impressions of that post just likes, comments, reactions... I use the metric parameters from the App Insights documentation but this is what i get in all the cases:
{
"data": [
{
"time": "2017-08-15T08:00:00+0000",
"value": "0"
},
{
"time": "2017-08-16T08:00:00+0000",
"value": "0"
},
{
"time": "2017-08-17T08:00:00+0000",
"value": "0"
},
{
"time": "2017-08-18T08:00:00+0000",
"value": "0"
},
{
"time": "2017-08-19T08:00:00+0000",
"value": "0"
},
{
"time": "2017-08-20T08:00:00+0000",
"value": "0"
},
{
"time": "2017-08-21T08:00:00+0000",
"value": "0"
}
]
}
I log in different test users accounts and see this specific post, create comments and put likes but there is no impressions... Can somebody help me with this problem? Thanks!

Get comments from facebook ads (marketing)

After I make an ads for my post on facebook ads manager.
Facebook Ads Manager show me how many comment belong to this ads. This is very important for me to verify the effective of my campaign.
In programing aspect: Is there's any way to count number belong to my ads like Facebook Ads Manager (I describe above). I have used both Java Facebook Ads SDK (Ads Insight module from https://github.com/facebook/facebook-java-ads-sdk) and Graph Explorer Tool, they both return "comment" field or "like" field not existed
Please help!
You can't get comments nor reactions from Marketing Insights directly.
I stand corrected. If you have access to an ad_account insights, then you can use Marketing API to get a post's comments directly. Thanks #lamxung55
Let's say you have and ad_id of 123000000
If you have a token with ads_management or ads_read permission, you can make a request to the Marketing API such as
/123000000?fields=creative.fields(effective_object_story_id),insights.fields(actions)
This will give you the effective_object_story_id which is the object_id of the post ({page_id}_{post_id}), and its insights including its actions broken down by action type. For example:
{
"creative": {
"effective_object_story_id": "456000000_789000000",
"id": "123000000"
},
"insights": {
"data": [
{
"actions": [
{
"action_type": "comment",
"value": "12"
},
{
"action_type": "like",
"value": "2"
},
{
"action_type": "post",
"value": "3"
},
{
"action_type": "post_reaction",
"value": "29"
},
{
"action_type": "video_view",
"value": "558"
},
{
"action_type": "page_engagement",
"value": "604"
},
{
"action_type": "post_engagement",
"value": "602"
}
],
"date_start": "2017-08-14",
"date_stop": "2017-08-20"
}
],
"paging": {
"cursors": {
"before": "xxx",
"after": "xxx"
}
}
}
}
The effective_object_story_id (so, post_id) is 456000000_789000000.
You can then query the comments edge of the post adding summary=true as a parameter. This endpoint is public for common posts (however, it won't work for non public posts)
/456000000_789000000/comments?summary=true
Which will respond with an object like
{
"data": [
<LOTS OF COMMENTS HERE>
],
"paging": {
<PAGING LINKS>
},
"summary": {
"order": "chronological",
"total_count": 50,
"can_comment": true
}
}
This means the post has had 50 comments, of which 12 were made through a paid action.
We can simply use this syntax to get adset comment: ...adset_id/insights?fields=actions. Another ads stuffs are the same

Access Additional Standard Event Parameters using FB Graph API Explorer

I've installed Facebook Pixel on my website, and it records purchases made on my site. The script on my site is the normal purchase standard event:
fbq('track', 'Purchase', {value: '0.00', currency: 'USD'});
Except that the 'value' is dynamic and changes for each order. I want to access these additional parameters using the FB Insights API (accessed through the Graph API Explorer).
Right now, my query looks like this:
act_1020149xxxxxxxxxxx/insights?level=ad&action_report_time=conversion&default_summary=true&fields=actions,spend,account_id,campaign_name,ad_name,adset_name,impressions&time_range[since]=2015-11-01&time_range[until]=2015-12-01
This returns data that looks like this:
{
"data": [
{
"actions": [
{
"action_type": "link_click",
"value": 19
},
{
"action_type": "offsite_conversion.fb_pixel_purchase",
"value": 1
},
{
"action_type": "offsite_conversion.fb_pixel_view_content",
"value": 19
},
{
"action_type": "post_like",
"value": 88
},
{
"action_type": "page_engagement",
"value": 107
},
{
"action_type": "post_engagement",
"value": 107
},
{
"action_type": "offsite_conversion",
"value": 20
}
],
"spend": 5.16,
"account_id": "10201496xxxxxxxxxx",
"campaign_name": "Link Clicks to Website (CPC)",
"ad_name": "[2015/11/27] New Arrivals",
"adset_name": "Custom Audience - Visitors or Lookalike - Visitors",
"impressions": "2634",
"date_start": "2015-11-01",
"date_stop": "2015-12-01"
}, ...
As you can see, the query returns purchases made on the site (offsite_conversion.fb_pixel_purchase) that came from the ad. How can I extend this query to also include the 'value' and 'currency' of each purchase, as captured in the standard event code embedded on my website.
If this isn't possible, then what part of the API should I use to find that data on purchases that I'm looking for?
You need to add the 'action_values' field to get the purchase value. The currency is the one you have registered with you account. If you report different currencies for different purchases (pixel fires) I would suppose that facebook convert the values to your currency.

How do you retrieve the "Place" field of a Facebook Graph Post object?

I am trying to retrieve the "Place" field of a Facebook Graph Post object from a Facebook friend. After obtaining an access token with the friends_status and read_stream permissions, I request from the Graph API like so:
http://graph.facebook.com/[user_id]_[post_id]
What is returned are some of the fields described in the Graph API docs for Post:
{
"id": "1164358582_2458311174854",
"from": {
"name": "Joe Blo",
"id": "1164358582"
},
"message": "Is pretty bummed today",
"actions": [
{
"name": "Comment",
"link": "http://www.facebook.com/1164358582/posts/2458311174854"
},
{
"name": "Like",
"link": "http://www.facebook.com/1164358582/posts/2458311174854"
}
],
"type": "status",
"application": {
"name": "Facebook for Android",
"id": "350685531721"
},
"created_time": "2011-11-20T03:23:04+0000",
"updated_time": "2011-11-20T12:12:49+0000",
"comments": {
"data": [
{
"id": "1164358582_2458311174852_2962531",
"from": {
"name": "Sue Candy",
"id": "1056617421"
},
"message": "OMG I'm so sorry!!!",
"created_time": "2011-11-20T03:25:06+0000"
}
],
"count": 1
}
}
This is all fine and dandy, except for the fact that when I see this Post within my Facebook stream, it also shows a location accompanying the post:
9 hours ago near El Reno, OK
I expected the El Reno, OK Place object returned as a field within this Post, but I don't see it.
In the Facebook Graph API Explorer, I've tried enabling almost every permission and I am not seeing any difference in the response (no "Place" field returned). Am I going about this incorrectly?
Not 100% sure but I think you can only get the "place" info if it is of type "checkin". I totally get where you are coming from, I wondered about that myself.
https://developers.facebook.com/tools/
Try the Graph API Explorer Tool if you haven't already looked at it.

Insights before 2010-04-02 are missing?

I'd like to get Insights data before 2010-04-02, but it seems to be impossible to retrieve via the Graph API or FQL query. If you make a Graph API request spanning over 2010-04-02 you will get results starting at 2010-04-02 and going forward with the rest simply missing. Can any one explain this or have a way to get around this limitation?
Here is an example of the problem: http://developers.facebook.com/tools/explorer/?method=GET&path=2439131959%2Finsights%2Fapplication_active_users%3Fsince%3D2010-03-28%26until%3D2010-04-10%26date_format%3DY-m-d
There should be results from 2010-03-28 to 2010-04-10, but you only get 2010-04-02 and onwards.
{
"data": [
{
"id": "2439131959/insights/application_active_users/day",
"name": "application_active_users",
"period": "day",
"values": [
{
"value": 172118,
"end_time": "2010-04-02"
},
{
"value": 177263,
"end_time": "2010-04-03"
},
{
"value": 176568,
"end_time": "2010-04-04"
},
{
"value": 190725,
"end_time": "2010-04-05"
},
...
Maybe your insights were a "victim" of this: https://developers.facebook.com/docs/reference/fql/insights/
We are deprecating some old insights. These metrics are marked as
deprecated throughout this document. After 12/21/2011, data for these
metrics won't be available prior to 07/19/2011 -- please download this
data before this 12/21/2011. These insights will be completely removed
from API after 02/15/2012.