• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 207
  • Last Modified:

Is it possible to obtainfacebook "Likes" data, to use in an application?


This is what I want to do: I have a webstore which contains various products. Against each product I want to add the "facebook like" bookmarking function.

What I then would like to do is allow users to sort products by the number of "likes".

Is this a feasible possibility and if so how would you best acomplish it?

I know that you can add the facebook like function direct, or you could use something like "add this" - would either / both provide a possible solution to do this?

What would your suggestions be?

  • 2
1 Solution
I think you would have to add a value to the database each time the like button is clicked, using a callback function


How do I know when a user clicks a Like button?

If you are using the XFBML version of the button, you can subscribe to the 'edge.create' event through FB.Event.subscribe.

ChilliSauceAuthor Commented:
Thanks for the advice.

Can you tell me if it is possible to pass a variable with a button click and get that variable in a call back?

EG suppose I have a variable "ProductID" which I can pass with a button, if I can get that variable back then I can just update the database with a count against that product ID.

Thanks in advance
You can grab anything on the page with javascript: form values, inner html, tag attributes, etc so your callback function could grab it that way.

So if you had

  <li>Product Id: <span id="product-id">11134</span></li>
  <li>Price: <span id="product-price">$23.99</span></li>

it would be something like

var productid = document.getElementById('product-id').innerHTML

I'm not a javascript expert though.
step1: you will require to add a column in database to count likes.
step2: add javascript function to insert like count in database
e.g. <span onclick='updatelike(productid)'>Like</span>
step3: function updatelike(productid) { // async call to execute handler
//here call a http handler and pass productid as querystring
//and you can write insert code on that handler, it will add to db
//e.g. updatelikecount.ashx?productid=yourproductid
step4:get the list of product from database and sort it by likes.

Let me know if you have any difficulty.

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now