Getting Video View Count from Facebook APIs - facebook

I'm trying to figure out which (if any) API will allow me to access Video View Count (views for a given facebook video). I've looked through the documentation for Atlas, Graph, and Marketing API but I can't seem to find any API call that would return this metric.
Was this stripped from the APIs after the issues surrounding the authenticity of the metrics arose a few months back?

Simply do an insights request for the post that includes the video. There are many metrics, all documented here.
You'll also need enough permissions to the page; you cannot look at someone else's posts' insights (therefore the example below will return empty data).
For example 127615610597242_1608135349211920/insights/post_video_views
Example output:
{
"data": [
{
"name": "post_video_views",
"period": "day",
"values": [
{
"value": 1111,
"end_time": "2016-11-24T08:00:00+0000"
},
{
"value": 2222,
"end_time": "2016-11-25T08:00:00+0000"
},
{
"value": 3333,
"end_time": "2016-11-26T08:00:00+0000"
}
],
"title": "Daily Total Video Views",
"description": "Daily: Total number of times your video was viewed for more than 3 seconds. (Total Count)",
"id": "127615610597242_1608135349211920/insights/post_video_views/day"
},
{
"name": "post_video_views",
"period": "lifetime",
"values": [
{
"value": 44444
}
],
"title": "Lifetime Total Video Views",
"description": "Lifetime: Total number of times your video was viewed for more than 3 seconds. (Total Count)",
"id": "127615610597242_1608135349211920/insights/post_video_views/lifetime"
}
]
}

Related

Getting two strange numbers in Facebook Page Insights

I am trying to get facebook page insights using Facebook Graph API, I see some strange numbers in page_cta_clicks_logged_in_total(looks like they are coming in all logged_in metrics)
Following is a sample Insight data from Facebook
{
"name": "page_cta_clicks_logged_in_total",
"period": "day",
"values": [
{
"value": {
"470946356598165": 0,
"156880401338097": 0
},
"end_time": "2017-12-13T08:00:00+0000"
},
{
"value": {
"470946356598165": 0,
"156880401338097": 2
},
"end_time": "2017-12-14T08:00:00+0000"
}
],
"title": "Daily Total CTA click count per Page",
"description": "Daily: Total CTA click count per Page",
"id": "<page_id>/insights/page_cta_clicks_logged_in_total/day"
}
what are the numbers 470946356598165 & 156880401338097
You get these ids with click related metrics (Ex. page_cta_clicks_by_age_gender_logged_in_unique, page_cta_clicks_logged_in_total, page_cta_clicks_logged_in_unique).
These ids are basically ids of the Page Buttons (look at the following image).
You can get the details of the button by doing following API call
https://graph.facebook.com/470946356598165?access_token=[access_token]
i see the following response
{
"id": "470946356598165",
"type": "MESSAGE",
"status": "ACTIVE"
}
You can check the node type of the id, through facebook graph api:
https://graph.facebook.com/470946356598165?metadata=1
https://graph.facebook.com/156880401338097?metadata=1
// response:
{
"id": "470946356598165",
...
"metadata": {
"fields": [
...
],
"type": "pagecalltoaction"
},
}
It gives us hints that the node type is pagecalltoaction, which is Page Call To Action.
See More: How can I know if a node returned from Facebook Graph API is a profile or a page?

How can I get all photos in one post in a page using Graph API?

For example this graph
https://graph.facebook.com/audi/posts?access_token=[ACCESS TOKEN]&fields=id,message,picture,link,name,description,type,icon,created_time,from,object_id&since=2016-10-14T17:54:17+0000&limit=1
will give you this result(after replace ACCESS TOKEN with your access token ) :
{
"data": [
{
"id": "96585976469_10153772437221470",
"message": "Take a night tour of Capitol Hill with the #AudiRS7. #AudiDuel",
"picture": "https://scontent.xx.fbcdn.net/v/t1.0-0/s130x130/14680669_10153772435521470_6025374941796908984_n.jpg?oh=3654e74f79914c9bb0fa596ce8434c46&oe=589E82B4",
"link": "https://www.facebook.com/audi/photos/a.101113351469.101662.96585976469/10153772435521470/?type=3",
"name": "Photos from Audi USA's post",
"type": "photo",
"icon": "https://www.facebook.com/images/icons/photo.gif",
"created_time": "2016-10-14T17:54:17+0000",
"from": {
"name": "Audi USA",
"id": "96585976469"
},
"object_id": "10153772435521470"
}
],
"paging": {
"previous": "https://graph.facebook.com/v2.5/96585976469/posts?fields=id,message,picture,link,name,description,type,icon,created_time,from,object_id&limit=1&since=1476467657&access_token=[ACCESS TOKEN]&__paging_token=[ACCESS TOKEN]&__previous=1",
"next": "https://graph.facebook.com/v2.5/96585976469/posts?fields=id,message,picture,link,name,description,type,icon,created_time,from,object_id&limit=1&since=2016-10-14T17\u00253A54\u00253A17+0000&access_token=[ACCESS TOKEN]&until=1476467657&__paging_token=[ACCESS TOKEN]"
}
}
and this is the link of the post
https://www.facebook.com/audi/posts/10153772437221470
it gave me just the first one photo but I need all photos in this post
attachments is the field you are looking for.
(Seems not officially documented, perhaps because those aggregate posts are special. But Graph API Explorer suggests it as one of the available fields.)

How far can I go back with Facebook Insight API?

I have been trying to get historical data for Facebook pages. I was wondering how to determine how far back I can go.
So I know I can go one month back. Is this a rolling window? I also would like to know how far I can go back and not get an api exception like follows.
{
"error": {
"message": "Unsupported operation",
"type": "FacebookApiException",
"code": 100
}
}
Is it possible to get all the historical insight data for a given fan page that I have access to.
Thanks and any suggestions that might help with understanding how to do this cleanly and robustly are also welcome.
Start with 30 days ending on the current day, e.g.
/278905338821044/insights/page_fans/lifetime?since=30 days ago&until=now
The response will have the last 30 days' data, and you can iteratively go through the 'previous' links in the paging structure at the end to go back into the past
{
"data": [
{
"id": "278905338821044/insights/page_fans/lifetime",
"name": "page_fans",
"period": "lifetime",
"values": [
{
"value": 1432,
"end_time": "2012-09-19T07:00:00+0000"
},
//snip
{
"value": 1438,
"end_time": "2012-10-16T07:00:00+0000"
}
],
"title": "Lifetime Total Likes",
"description": "Lifetime The total number of people who have liked your Page. (Unique Users)"
}
],
"paging": {
"previous": "https://graph.facebook.com/278905338821044/insights/page_fans/lifetime?since=1345405748&until=1347997748",
"next": "https://graph.facebook.com/278905338821044/insights/page_fans/lifetime?since=1350589748&until=1353181748"
}
}

Way to find Facebook reach from my app posts?

Is there a way to retrieve the reach from my App posts?
Example:
My app posts photos on a specific fan page, I would like to retrieve the reach that my app provided to that fanpage in order to show them how awesome my app is.
Using the page access token for the page you manage, (with read_insights Permission).
You can then access /POST_ID/insights to retrieve insights information about that post.
For a sample post on my page, this returns the impressions data for the post.
Excerpt:
{
"id": "[ID REMOVED]/insights/post_story_adds_by_action_type/lifetime",
"name": "post_story_adds_by_action_type",
"period": "lifetime",
"values": [
{
"value": {
"like": 20,
"comment": 3,
"share": 1
}
}
],
"title": "Lifetime Post Stories by action type",
"description": "Lifetime The number of stories created about your Page post, by action type. (Total Count)"
},
{
"id": "[ID REMOVED]/insights/post_impressions_unique/lifetime",
"name": "post_impressions_unique",
"period": "lifetime",
"values": [
{
"value": 936
}
],
"title": "Lifetime Post Total Reach",
"description": "Lifetime The number of people who saw your Page post. (Unique Users)"
},
{
"id": "[ID REMOVED]/insights/post_impressions/lifetime",
"name": "post_impressions",
"period": "lifetime",
"values": [
{
"value": 2936
}
],
"title": "Lifetime Post Total Impressions",
"description": "Lifetime The number of impressions of your Page post. (Total Count)"
},
The blog post from when this was launched is here: https://developers.facebook.com/blog/post/573/
And the insights connection is mentioned in the Post documentation

Facebook Graph API - Get like count on page/group photos

I've been testing graph API and ran into a problem. How can I get like count from photos of a page/group?
I'm administrator/creator of a group. When entering in https://developers.facebook.com/tools/explorer/ certain photo ID from that group it brings almost all data, even comments, but not the like count. For like part it needs (according to docs) access token despite the fact that anyone can access that info.
How to get access token of my page/group with required permissions and how to use it to get info I need?
If possible I would like to get JSON from a single address if it is possible.
This is possible with a page (even without an access token!) and here's how:
Visit the page on the graph
Get the page's id by going to the page's url:
https://www.facebook.com/pages/platform/19292868552
The number on the end of the URL is the page's id. Take that id and use it with the graph explorer (here) or just visit it directly.
Visit the page's albums
Now appending albums to that url will give you all the albums the page has, including wall photos:
https://graph.facebook.com/19292868552/albums
The output looks like this:
{
"data": [
{
"id": "10150160810478553",
"from": {
"name": "Facebook Platform",
"category": "Product/service",
"id": "19292868552"
},
"name": "Bringing Operation Developer Love to Europe",
"description": "Blog post: http://developers.facebook.com/blog/post/479\n\nVideos and presentations uploaded here: http://developers.facebook.com/videos/",
"location": "Berlin, Paris, London",
"link": "https://www.facebook.com/album.php?fbid=10150160810478553&id=19292868552&aid=285301",
"cover_photo": "10150160811078553",
"count": 32,
"type": "normal",
"created_time": "2011-04-06T23:05:44+0000",
"updated_time": "2011-04-06T23:33:20+0000",
"comments": {
..... etc ....
Selecting an album
For each object in the data array there is an id and a name. Using these two fields you can select the album that contains the photos you want. The first album in this result is "Bringing Operation Developer Love to Europe". Lets look at this albums photos.
Seeing Photos
If you've followed the answer up to this point the next step should be fairly obvious. Use the id for the album you want and append photos to the graph url:
https://graph.facebook.com/10150160810478553/photos
Seeing a Photo's likes
Much like selecting an album, simply use an id in the output of the above step and append likes to the url to see a photos likes:
https://graph.facebook.com/10150160813853553/likes
Output:
{
"data": [
{
"id": "1163036945",
"name": "Aditya Pn"
},
{
"id": "1555885347",
"name": "Nadin M\u00f6ller"
},
{
"id": "100001643068103",
"name": "Umut Ayg\u00fcn"
},
{
"id": "100000165334510",
"name": "Alessandra Milfont"
},
{
"id": "100001472353494",
"name": "Sayer Mohammad Naz"
},
{
"id": "1051008973",
"name": "Jenson Daniel Chambi"
},
{
"id": "100000233515895",
"name": "Ruby Atiga"
},
Using this output you can simply count the number of entries in the data array to get the like count.
Note that all of this is possible from using the graph explorer by clicking on ids in the output box and the connections sidebar (except for the last /likes connection, which will hopefully be added soon. I hope this helps. Also, you do not need an access token to do any of this because pages are public. Hope this helps!
You can get the comments/likes count without having to paginate through all likes by using the fields parameter in combination with likes.limit(1).summary(true). For example, a search api query for pizza below will give you all public posts and their likes count summarized:
https://graph.facebook.com/search?q=pizza&type=post&fields=id,name,likes.limit(1).summary(true)
results (truncated):
{
"data": [
{
"id": "47883936273_659693910762305",
"name": "Instagram",
"created_time": "2014-02-16T01:15:29+0000",
"likes": {
"data": [
{
"id": "100002243084532",
"name": "Yvette Martin"
}
],
"paging": {
"cursors": {
"after": "MTAwMDAyMjQzMDg0NTMy",
"before": "MTAwMDAyMjQzMDg0NTMy"
},
"next": "https://graph.facebook.com/47883936273_659693910762305/likes?limit=1&summary=1&after=MTAwMDAyMjQzMDg0NTMy"
},
"summary": {
"total_count": 13682
}
}
},
{
"id": "136336876521150_314001148754721",
"name": "Pizza Box Turns into Plates & Storage Unit!",
"created_time": "2014-02-15T21:20:00+0000",
"likes": {
"data": [
{
"id": "100005373008864",
"name": "Liliana Campoli"
}
],
"paging": {
"cursors": {
"after": "MTAwMDA1MzczMDA4ODY0",
"before": "MTAwMDA1MzczMDA4ODY0"
},
"next": "https://graph.facebook.com/136336876521150_314001148754721/likes?limit=1&summary=1&after=MTAwMDA1MzczMDA4ODY0"
},
"summary": {
"total_count": 2792
}
}
}
/me/feed returns a LIKES field
I used a solution where I simply find the number of items in the array which display LIKES
Object.keys(item.likes.data).length
This returns the "length" of an object -- which is equal to the number of likes.
http://graph.facebook.com/223766074374957
there is a likes property in the response
{
"name": "Bejeweled Blitz",
"is_published": true,
"website": "https://apps.facebook.com/bejeweledblitz/",
"username": "bejeweledblitz",
"products": "Bejeweled Blitz\nBejeweled\nPlants vs. Zombies\nPeggle\nZuma\nChuzzle\nBookworm Adventures\n \nFor a complete list, please visit www.popcap.com\n ",
"about": "We're the award-winning hit, Bejeweled Blitz! The lightning-fast puzzle game where you have just 60-seconds to match as many gems as you can! Start Blitzing now!",
"general_info": "Speed is the name of the game in Bejeweled Blitz! Bejeweled Blitz is a speedier take on the classic Bejeweled match-3 gem game mechanic. Your goal is to make as many matches as you can in 60-seconds to really make your score soar! But you won't be going it alone! There are special ways to enhance your Bejeweled Blitz game - like Boosts (power-ups like Scrambler, which moves all the gems around the board or +5 seconds, to add 5 seconds more gem-matching time!) and the popular, Rare Gems. Rare Gems are like extra-special power-ups that can REALLY take your game to the next level!",
"talking_about_count": 22487,
"category": "App page",
"id": "223766074374957",
"link": "https://www.facebook.com/bejeweledblitz",
"likes": 5796324,
"cover": {
"cover_id": 383412771743619,
"source": "http://sphotos-c.ak.fbcdn.net/hphotos-ak-ash4/s720x720/417018_383412771743619_1056862875_n.jpg",
"offset_y": 0
}
}