How to implement Facebook Like funtionality in drupal?

There are two ways to implement Facebook likes functionality in your project.

1. First of all it requires a Facebook Url for which you want to display likes count.
    Example:- www.facebook.com/xyz  //Here xyz could be anything.

2. If you want like count numbers with like button in your website then you need to get code from here. Provide the Url(Ex. www.facebook.com/xyz) and select other options as par your requirement.

3. Now Click get code.You will get 2 codes. First one is the Java-script code. You need to put this code in your html head tag.

4. The other code you need to put wherever you want to display like button and its count.

The requirement which I got to implement Facebook like functionality was bit different. I wanted to display only Facebook like count, and not to display like button. For this I have these solutions:-

1. You should use FQL(Facebook Query Language) here. Use the following code:-
https://api.facebook.com/method/fql.query?query=select like_count from link_stat where
url = “http://www.facebook.com/xyz”    // Change this Url

2. Pass this Url inside drupal_http_request() function and use json_decode() to get the value of like count. Then display it wherever you want.

3.You can get the like count by using this code also.
https://graph.facebook.com/?id=your_fb_page_id  // This id should be your page id in Facebook

4. Pass this Url inside drupal_http_request() function and use json_decode() to get the value of like count. Then display it wherever you want.

   

No comments:

Post a Comment