This post in by Clint Watson, our founder and lead developer.
If you're not a geek - here's the bottom line of this post: The Facebook "like" buttons you see embedded on websites incorrectly report the number of "people" who "like" something.
Specifically, the button can inflate the displayed count of people. While this is fine when all you want to do is track some general level of "engagement" with a particular item, it was not accurate for the use I needed - counting each "like" as a vote in our BoldBrush Online painting competition
. What I needed is a way to get the number of actual people
who "like" something. And there is
a way to retreive that information from Facebook, but it is often a different number from what is shown on the "like" button itself. If you are a geek - here's the bottom line of this post:
If you're using the Facebook "Like" Button Social Plugin and you need an accurate count of the actual number of people
who have clicked the "like" button, you can't rely on the number reported by the button itself. You need to retrieve your URL's "fan count" number via Facebook's Open Graph API Background
When I started our online painting contest, I had always planned to roll out a feature that allowed users to vote for their favorite paintings - eventually maybe creating some sort of people's choice award category. When Facebook released the "Like" button social plugin, I thought it would be simpler to just use their code. Plus, I thought, it would solve some problems. I had always worried about implementing the feature myself because if awards were tied to the voting, there would be incentive to "game the system" and I just didn't want to deal with a bunch of fake user accounts and identity verification issues that would arise because of the gaming. So I thought since most people use their real identities on Facebook, using the Facebook like button would largely solve the issue for me.
I recently added that feature to our online painting competition. It lets Facebook users to "like" their favorite paintings. After a few weeks, I thought it would be fun to use those "like" counts to rank the paintings in order of popularity, with the "most popular" being the ones with the most "likes." So I dug into Facebook's api and found a way to retrieve the "like" data and hacked together a working solution. So far so good. The users were having a good time, it was interesting to watch the rankings change over time. I also decided not to tie any awards to these rankings (at least for now) since I didn't know how accurate the "like" data actually was - I'm glad I didn't. Like Button Inconsistencies
If you properly register your application with Facebook, the like button gives the application owner access to an administrative page for each item on his website that has been "liked." I quickly started to notice something odd. One of the early top-ranking paintings displayed 331 "likes" on the button itself. This number matched what I was pulling from the api and was storing in my own database for ranking purposes. But when I clicked through to the adminitrative page for that item, it clearly displayed "140 People like this." There's a pretty big difference between 140 and 331 - way too big a difference if awards get involved.
At this point, I wasn't too worried since it was just for fun upon the initial launch, but with future uses in mind, I decided to dive-in and create a more controlled situation and see if I could figure out what was going on. Duplicating the Problem
I visited a painting page that had no "likes" so far. I also picked a time when contest activity was low (it tends to be frantic toward deadlines and slow right after one contest ends and the next one starts). I also created a fake Facebook account (shhh don't tell Zuck) so that I could use my real account and the fake account to have data from two different Facebook users.
While logged into Facebook with the fake "B Rockhurst" account, I visited the web page and clicked "Like." The next thing that happed was that the like button opened up a text box to allow me to type a message and "share" the item on my Facebook wall. So I typed "cool" and hit submit.
Here's what the like button displays at this point: "B Rockhurst and one other person
So what's going on? To find out, I called Facebook's handy api
. For this particular call I used the old REST api call in the following format: http://api.facebook.com/restserver.php?method=links.getStats&urls=URL_OF_MY_WEBPAGE Which returned the following XML:
Notice the "like_count" actually returns 1. But and the "share_count" also returns 1. That is correct. "B Rockhurst" "liked" the page once and shared it once. It seems, however, that the Facebook "Like" Button Social Plugin displays the "total_count" - which is now 2
. In fact, I was already aware of this issue and had been using the "total_count" for my painting rankings so that the numbers would match the reported Facebook like button counts. I figured, in essence, everybody was allowed two votes - a "like" and a "share." And had decided not to worry about it until I had more time to study it.
Next I logged into Facebook under my real account. I visited "B Rockhurst's" profile and I clicked "like" under the shared item on his wall: Then I called the API again, but alas, no change.
Apparently "liking" an item on another's wall doesn't inflate the count (somewhat ironically since this actually is an instance of another person "liking" the item). OK, so what if I tried commenting?
So I commented on "B Rockhurst's" item by writing "pretty cool":
Again - checked the API - no change in the counts.
Hmmm. what if I shared
the item directly from "Barrett's" wall? Let's check the API again:
Bingo! The "share_count" has now increased to 2 and the "total_count" has increased to 3. Let's confirm. I visit the web page again, this time logged into Facebook as myself:
As you can see, the button total still matches the api total. It reports that "3 people like this" - even though only 2 people have been involved and only 1 person (B Rockhurst) has actually clicked the like button on the web page itself. Now, logged in as myself, I click "Like" and when the dialog box pops up I share it to my facebook wall: If my suspicions are correct, the number of "people" that the "like" button will report, should increase to five now
(since the like button reports the "total_count" field). Here's the api call: So if the like button counts are wrong, how do we get the right number (which at this point should be two people)?
The answer, I think, likes in the fact that each URL "liked" on Facebook actually becomes a "fan page." As the administrator of the application providing the like button, I get access to that fan page. So, let's visit the fan page and see what it says: That's perfect! That's exactly what I want. 2 people have actually visited the web page and clicked like. Can we get this information via the api?
One would think, based on looking at the api calls above, you could use the "like_count" shown. However, I knew from past experience that there is an issue with that number. I waited a couple of days and checked the api again: What? The "like_count" has now increased to four?
And the "total_count" (the number reported on the button itself) has now increased to seven? Did more people actually visit the page and "like" it? Let's check the admin page:
I honestly haven't totally figured out why the "like_count" increases that way. Perhaps some of the earlier actions I took did
increase the like count, but maybe you have to give them time to show up in the API. I do
know that the like count does
inflate beyond the actual number of people, and so, I can't use it for my intended purpose. Since, for the purpose of the actual number of people, the button count is wrong, the "like_count" is wrong - can we get the correct number from the api? The Solution The answer is yes, but, as far as I can determine, we have to make a different api call to the newer open graph api: https://graph.facebook.com/URL_OF_MY_WEBPAGE This api call results in the following, this time as a JSON object:
The "fan_count" number is what we want.
UPDATE 12/27/2010 - Facebook has changed the way they return this information from their API. The URL to the api call remains the same, but they have ended the field "fan_count" and replaced it with a field called "likes" (so that the example above would now read "likes" : 2 ). Other than this one change the data remains the same. Bottom Line for Our Use
I don't have an issue with the way the Facebook button normally reports the numbers - it's probably a good number for tracking an approximation of "engagement
" with a particular item, although reporting the number as the "number of people
" who "liked" an item seems a bit misleading.
However, in a situation where you want an accurate count or where there might be an incentive to game the system, the "fan_count" number is the one you really want to use.
In the end, I'll probably end up building our own voting system as it would provide more control and other useful data, but in the meantime, it's nice to know we can get more accurate numbers from the existing Facebook "like" buttons by changing our api calls. Clint Watson
Software Craftsman and Art Fanatic Footnotes:
1. The open graph api call is https://graph.facebook.com/URL_OF_YOUR_WEBPAGE
2. I don't think anyone has tried to game the system so far. I think the number inflation has been a result of people naturally encouraging their friends to go "like" their paintings, which is fine.
3. I would have preferred to use the open graph api for all the calls, however, the old api let me pass multiple URLs in one call and it seems that the open graph api must be called one URL at a time. It's not going to be impossible, but I'm going to have to make a lot more calls to Facebook's api to retreive the data I need if I have to get one url at a time. If someone knows of a way to call open graph with multiple URLs, I would love to know the call. UPDATE 7/21/2010
- Duh, the call is easy it's https://graph.facebook.com/?ids=URL,URL,URL etc. We've now implemented the solution outlined in this post.
4. If Facebook was a smaller company, one might conjecture that they have an incentive to show the larger (but more inaccurate) number on the "Like" button because it is a publicly visible number that is more impressive. That higher number might encourage other webmasters to implement the like button, thus increasing the uptake of the button itself. On the other hand, making such a suggestion seems silly given that Facebook has 500 million users and is the most trafficked site on the Internet...savvy webmasters should already understand the value of engaging with the Internet's largest community.