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

4

13

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.

Floriated answered 8/8, 2011 at 15:27 Comment(2)
Maybe this solution here will be of help to you: https://mcmap.net/q/903665/-facebook-graph-api-photo-like-count-without-pagingBedim
#19058222 Perfectly works.Lavettelavigne
C
28

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!

Castled answered 11/8, 2011 at 16:57 Comment(6)
i think if there're more than 25 likes for an object, facebook will return the likes in pages, so we'll have to traverse all these links to get the total likes. that could take a lot of time!Ellerd
just found out that you can add the limit param to the URL to get all likes in one response: graph.facebook.com/98423808305/likes?limit=100000000Ellerd
@ThiDuongNguyen that will return up to 100000000 entries while what you actually want is just a number. When you get the photo from the feed number of likes appears in a count field under likes, so there must be another way (instead of searching the feed or parsing a large JSONObject)Palmary
But this response is not consistent. Some IDs will return "likes" as a number, but other IDs will return "likes" as a list of users. Counting through millions of users per entity is not realistic. For example: graph.facebook.com/20531316728?fields=likes "likes": 84984656 graph.facebook.com/10151255420886749?fields=likes "likes": big-ass listAsparagus
is it possible to know the exact like number of a video?Offcolor
This should not be the accepted answer. Facebook allows for ".summary(true)" on the likes field. So doing /{photo-id}?fields=likes.summary(true) will return a response with the field .summary.total_countAponeurosis
C
6

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
        }
      }
    }
Centigrade answered 20/2, 2014 at 20:12 Comment(1)
Is it possible to get shares too?Triptych
L
1

/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.

Leptospirosis answered 18/4, 2014 at 18:10 Comment(0)
M
-1

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
   }
}
Mumps answered 30/11, 2012 at 4:46 Comment(3)
@konpsych its their fan pageElectrocardiograph
@JeyKeu the question is about like count of photos that's why I am askingPalmary
This just gives you the like count of page not photoLavettelavigne

© 2022 - 2024 — McMap. All rights reserved.