I've looked through Facebook Graph API documentation and a few related topics such as this, this and even this. However I haven't found any solution.
I'm trying to analyse comments from this post. As you can see there are dozens of comments under that post. What I want to achieve is that I want to be able to retrieve some number of comments by giving start/end dates to request. For instance, by giving an HTTP request with parameter since=1375315200 (unix time) I expect to get all comments staring from 2013-08-01 (which is 1375315200 in unix time). However the following HTTP request:
curl -i -X GET "https://graph.facebook.com/v2.5/10151775534413086/comments?fields=created_time&offset=0&since=1375315200&limit=5&access_token={MY_TOKEN_HERE}"
Gives me the wrong result:
{
"data": [
{
"created_time": "2013-07-09T14:17:20+0000",
"id": SOME_ID_HERE
},
{
"created_time": "2013-07-09T18:03:17+0000",
"id": SOME_ID_HERE
},
{
"created_time": "2013-07-09T14:13:52+0000",
"id": SOME_ID_HERE
},
{
"created_time": "2013-07-09T14:22:16+0000",
"id": SOME_ID_HERE
},
{
"created_time": "2013-07-09T14:13:26+0000",
"id": SOME_ID_HERE
}
],
"paging": { CURSORS DATA HERE }
}
Why does this result contain entries before 2013-08-01 (timestamps are less than 1375315200)? Shouldn't that timestamps be later than 2013-08-01 (timestamps are greater than 1375315200)? Is there any ideas/solutions how to do about this issue?
Related
As Facebook released the new reaction{NONE, LIKE, LOVE, WOW, HAHA, SAD, ANGRY} feature for post, but I can not figure out to get all reaction counts in single graph API request.
Has anyone figured out a way to get this detailed reactions per post in single request?
The approach introduced by #CBroe appears to be working using Multiple ID Read Requests.
?ids=7175346442_10153799389241443,7175346442_10153799470326443&fields=reactions.type(LOVE).limit(0).summary(total_count).as(reactions_love),reactions.type(WOW).limit(0).summary(total_count).as(reactions_wow),reactions.type(HAHA).limit(0).summary(total_count).as(reactions_haha),...
Screenshot from Facebook Graph API Explorer:
Once a collection of posts is retrieved, one should be able to read reaction counts grouped by type using a single request. Note, the current limit of ids in the Multiple ID Read Request pattern is 50.
Theoretically possible using Field Expansion in combination with Field Aliases, like this:
?fields=reactions.type(LIKE).limit(0).summary(1).as(like),
reactions.type(WOW).limit(0).summary(1).as(wow),
reactions.type(SAD).limit(0).summary(1).as(sad),…
But there still seem to be some bugs in that regard; I frequently got “An unknown error has occurred” while testing this; f.e. replacing the limit value for LIKE with 1 in the above query triggers it …
Simply use the following as part of your graph query
fbpageid/posts?fields=created_time,story,message,shares,reactions.type(LIKE).limit(0).summary(1).as(like),reactions.type(LOVE).limit(0).summary(1).as(love),reactions.type(HAHA).limit(0).summary(1).as(haha),reactions.type(WOW).limit(0).summary(1).as(wow),reactions.type(SAD).limit(0).summary(1).as(sad),reactions.type(ANGRY).limit(0).summary(1).as(angry)&limit=10
So I'll be getting Post ID, Created time, Story, Message, Share Count, reaction count (currently 6 reaction) using only 1 query. It works with APi v2.9 as well
If you have read_insights permission, you could get reactions in following way for feed or a post
fields=insights.metric(post_reactions_by_type_total).period(lifetime).as(post_reactions_by_type_total)
and you would get results like:
"name": "post_reactions_by_type_total",
"period": "lifetime",
"values": [
{
"value": {
"like": 10,
"love": 2,
"wow": 3,
"haha": 1,
"sorry": 1,
"anger": 2
}
}
],
I found a way to achieve this with 1 request:
GET /{userId}?fields=
posts.as(like){reactions.type(LIKE).limit(0).summary(true)},
posts.as(love){reactions.type(LOVE).limit(0).summary(true)},
posts.as(wow){reactions.type(WOW).limit(0).summary(true)},
posts.as(haha){reactions.type(HAHA).limit(0).summary(true)},
posts.as(sad){reactions.type(SAD).limit(0).summary(true)},
posts.as(angry){reactions.type(ANGRY).limit(0).summary(true)},
posts.as(thankful){reactions.type(THANKFUL).limit(0).summary(true)}
This way you will receive 7 lists of posts (one per each reaction). Example:
{
"like": {
"data": [<list of posts>]
},
"love": {
"data": [<list of posts>]
},
"wow": {
"data": [<list of posts>]
},
"haha": {
"data": [<list of posts>]
},
"sad": {
"data": [<list of posts>]
},
"angry": {
"data": [<list of posts>]
},
"thankful": {
"data": [<list of posts>]
},
"paging": {
"previous": "...",
"next": "..."
},
"id": "<userId>"
}
I'm trying to figure out how to access the guest list data of an event on Facebook and the example given in the Facebook documentation located at https://developers.facebook.com/docs/reference/api/event/ is:
https://graph.facebook.com/331218348435/invited
However, when I test this in the explorer I get:
{
"error": "Request failed"
}
Am I missing something?
The endpoint is most definitely not deprecated.
The problem here is that there are simply too many people invited to that event! There are too many results to return in a single query...
If you specify a limit you will get the results you need:
https://graph.facebook.com/331218348435/invited?limit=10
The response for that request would be something like this :
{
"data": [
{
"name": "xxx",
"rsvp_status": "attending",
"id": "111"
},
{
"name": "yyy",
"rsvp_status": "attending",
"id": "222"
},
... (8 more results) ...
],
"paging": {
"next": "https://graph.facebook.com/331218348435/invited?limit=10&offset=10&__after_id=29606639"
}
}
Note that there is a paging result returned as well - this is the URL you will need to query in order to get the next batch of results. It uses the limit parameter and also the offset parameter to ensure that you don't get duplicate results.
In my example, I've given a limit of 10 users per response, but I've managed to get data even when specifying 1000 results. The bigger the limit you provide the longer the request will take to return data.
I have been working on a Facebook app for the last couple of weeks. I have successfully posted data to Facebook's Graph API but I have been struggling to get back specific fields. I am using the API explorer to test my various GET attempts. Here's an excerpt of the data that is returned with the api call: me/g_music:listen_to?fields=data
{
"data": [
{
"data": {
"song": {
"id": "355308601243965",
"url": "https://g8-music.herokuapp.com/object/song.php?title=Pierce+The+Veil+-+Bulls+in+the+Bronx&description=Played+On+G8-Music+for+Windows+8.&image=http%3A%2F%2Fuserserve-ak.last.fm%2Fserve%2F174s%2F78366946.jpg",
"type": "g_music:song",
"title": "Pierce The Veil - Bulls in the Bronx"
}
},
"id": "245964195537372"
},
{
"data": {
"song": {
"id": "365613963536278",
"url": "https://g8-music.herokuapp.com/object/song.php?title=Pierce+The+Veil+-+Kings+for+a+Day+%28feat.+Kellin+Quinn%29&description=Played+On+G8-Music+for+Windows+8.&image=http%3A%2F%2Fuserserve-ak.last.fm%2Fserve%2F174s%2F78366946.jpg",
"type": "g_music:song",
"title": "Pierce The Veil - Kings for a Day (feat. Kellin Quinn)"
}
},
"id": "245961632204295"
},
I am attempting to get the value of title but have been unsuccessful so far.
If I try something like: me/g_music:listen_to?fields=data.data... I receive an exception which tells me that "Subfields are not supported by data".
I am relatively new to the graph API so I'm most likely missing something obvious.
You are not missing anything. I verified this through the Graph API Explorer.
Subfields are not supported by data
But you have the whole data, simply fetch the title from the array.
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"
}
}
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
}
}