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

Posted on 2011-05-05
Last Modified: 2012-05-11

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?

Question by:ChilliSauce
    LVL 31

    Expert Comment

    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.

    Author Comment

    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
    LVL 31

    Expert Comment

    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.
    LVL 5

    Accepted Solution

    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.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    With a software solution, you always get to control email signatures and have the final say on the design - not an unrelated department or the uninterested end user.
    Read about why website design really matters in today's demanding market.
    Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
    Use Wufoo, an online form creation tool, to make powerful forms. Learn how to selectively show certain fields based on user input using rules to gather relevant information and data from your forms. The rules feature provides you with an opportunity…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now