How to get images field from a Group Feed - Facebook Graph API - facebook

I have been using Graph API for a while, but I am not able to figure this one out.
I have a group id, from whose feed I want to get the image urls for all available resolutions.
I know I can do that using the 'images' field of a photo id.
Here is a sample code which gets the id
<group-id>/feed?fields=attachments{target{id}}
I tried
<group-id>/feed?fields=attachments{target{id{images}}}
and also this
<group-id>/feed?fields=attachments.fields(target.fields(id{images}))
and this
<group-id>/feed?fields=attachments.fields(target.fields(id.fields(images)))
All of them return the JSON having the id, but not the images details I need.
I hope I have provided enough information.

You can use the below format while calling the API and it will return you with the images URL included in the post
<group-id>/feed?fields=created_time,attachments,message
You will get the response in the below format.
{
"created_time": "2017-11-16T06:21:37+0000",
"id": "543993212434753_1004360179731385",
"attachments": {
"data": [
{
"description": "Best #ethnic wear store for #women.
Shop Now>> sairandhri.com",
"media": {
"image": {
"height": 720,
"src": "https://scontent.xx.fbcdn.net/v/t1.0-9/s720x720/23519069_887109751445971_6170575397465061641_n.jpg?oh=170436ae447ec615f547d700017c67b4&oe=5AA4F844",
"width": 537
}
},
"target": {
"id": "887109751445971",
"url": "https://www.facebook.com/SairandhriShowroom/photos/a.302015823288703.1073741828.300462640110688/887109751445971/?type=3"
},
"type": "photo",
"url": "https://www.facebook.com/SairandhriShowroom/photos/a.302015823288703.1073741828.300462640110688/887109751445971/?type=3"
}
]
}
}
Its working and tested on Graph API Explorer

Related

Facebook for developers, get url from photo param

I'm trying the API Graph explorer, I'd like the photos param to give back the photo url but I can't set it in the GET request which currently is graph.facebook.com/v2.9/me?fields=id,name,photos
"id": "22331427282551006",
"name": "USER",
"photos": {
"data": [
{
"created_time": "2017-07-01T03:36:09+0000",
"id": "85419012312312"
},
{
"created_time": "2016-06-21T04:23:13+0000",
"id": "10112312312312311"
},
{
"created_time": "2016-01-31T13:03:50+0000",
"id": "12207150957211111"
},
{
"created_time": "2014-10-06T04:30:04+0000",
"id": "12312312312312312"
Also tried graph.facebook.com/v2.9/me?fields=id,name,photos?type=uploaded as said in this reference to get uploaded photos with unexpected errors.
You want the content of the images field below the photos edge, so you need to ask for that explicitly as well.
me?fields=id,name,photos{images}
If you need more sub-fields of the photos edge, then you need to include those as well, comma-separated.
https://developers.facebook.com/docs/graph-api/using-graph-api/#fieldexpansion

Facebook GraphAPI picture/full_picture permanent link

How can I get a permanent link for pictures in a post? For example, I can get all information about one post:
912163612218997/?fields=picture,full_picture,attachments
{
"picture": "https://scontent.xx.fbcdn.net/v/t1.0-0/s130x130/15390764_10154771322382505_5131571043698309499_n.jpg?oh=de4126b3944deb9fb7fca6b534e5e987&oe=58E45F29",
"full_picture": "https://scontent.xx.fbcdn.net/v/t31.0-8/s720x720/15326300_10154771322382505_5131571043698309499_o.jpg?oh=414291d1c1fbc88988afb887177a03c5&oe=59156F5D",
"id": "189675924467773_912163612218997",
"attachments": {
"data": [
{
"description": ...,
"media": {
"image": {
"height": 372,
"src": "https://scontent.xx.fbcdn.net/v/t31.0-8/s720x720/15326300_10154771322382505_5131571043698309499_o.jpg?oh=414291d1c1fbc88988afb887177a03c5&oe=59156F5D",
"width": 720
}
},
"target": {
"id": "10154771322382505",
"url": "https://www.facebook.com/photo.php?fbid=10154771322382505&set=gm.912163612218997&type=3"
},
"type": "photo",
"url": "https://www.facebook.com/photo.php?fbid=10154771322382505&set=gm.912163612218997&type=3"
}
]
}
}
However, these picture links are temporary. It won't be available after several hours.
Is there any way to get the permanent picture URL from Facebook GraphAPI?
I sort of figure out a workaround using redirect:
Fire graph API using object id and get CDN URL
Redirect to the CDN URL
Basically, as long as we know the object id, we can get the URL. Unfortunately, it is a bit slow.

Facebook Graph Api - Retrieve only Wall posts that contain a photo

I need to retrieve wall posts from Facebook for a given account, but I'm only interested in posts that contain a photo. Is there a way to add such a filter to a Facebook graph api query? Something like:
https://graph.facebook.com/DigitasLBiNL?fields=feed&type=photo
The facebook data contains a type property which comes back as photo, so I would think this would be possible, but I haven't had any luck going through the facebook sdk documentation or tinkering around.
I know I could do the filtering myself, but I'd prefer to be able to keep the paging property that facebook returns.
The edges
/{user_id}/home (https://developers.facebook.com/docs/graph-api/reference/v2.1/user/home#read)
/{user_id}/feed (https://developers.facebook.com/docs/graph-api/reference/v2.1/user/feed#read)
should (as per documentation) both be able to take a filter paramenter, containing filter keys from the stream_filter FQL table (https://developers.facebook.com/docs/reference/fql/stream_filter/).
If I run the FQL
select name, value, type, filter_key from stream_filter where uid=me()
I get the following result:
{
"data": [
{
"name": "News Feed",
"value": null,
"type": "newsfeed",
"filter_key": "nf"
},
{
"name": "Status Updates",
"value": 2915120374,
"type": "application",
"filter_key": "app_2915120374"
},
{
"name": "Photos",
"value": 2305272732,
"type": "application",
"filter_key": "app_2305272732"
},
{
"name": "Links",
"value": 2309869772,
"type": "application",
"filter_key": "app_2309869772"
},
{
"name": "Pages",
"value": null,
"type": "public_profiles",
"filter_key": "pp"
},
{
"name": "Video",
"value": 2392950137,
"type": "application",
"filter_key": "app_2392950137"
},
{
"name": "Notes",
"value": 2347471856,
"type": "application",
"filter_key": "app_2347471856"
},
{
"name": "Groups",
"value": 2361831622,
"type": "application",
"filter_key": "app_2361831622"
}
]
}
So, if I choose app_2305272732 as filter key for the photos, I am able to run the follwoing Graph API request successfully:
/me/home?filter=app_2305272732&limit=3
This gives me the three most recent photo posts from my newsfeed.
You want to do this for User/Page feeds (Pages are not supported for filtering according to the docs at https://developers.facebook.com/docs/graph-api/reference/v2.1/page/feed#read), so I tried this:
/me/feed?filter=app_2305272732&limit=3
Unfortunately, this doesn't return only photo posts, at least for me. So I think this is a bug in the Facebook Graph API.
According to
https://developers.facebook.com/docs/graph-api/reference/stream-filter/
you can use the type filter with value photo

Facebook Graph API - Getting Data from Subfields

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.

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
}
}