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

JackLeo picture JackLeo · Aug 8, 2011 · Viewed 47.2k times · Source

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.

Answer

squinlan picture squinlan · Aug 11, 2011

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!