Introduction

This article explains how to use the Like button of Facebook in your Web API application. Here we just get the code from Facebook and add it into the View of the application. The Like Button simply shares the content with friends on Facebook.

Procedure for adding the Like Button to an application:

  1. First create a Facebook account; if you have already then login with that account.
  2. Now open this link:

    https://developers.facebook.com/docs/plugins/like-button/

    The page will open like this:

    Like Button Page
  1. Now fill in the Like button form for displaying the Like button.

    Fill Like button Form
  1. Now for getting the code click on the "Get Code" button.

    Code Display
  1. Create the Web API application:
  1. Now copy the code and paste it into the "index.cshtml" file.

Paste in the following code:

  1. <!DOCTYPE html>
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <title>Facebook Like Button</title>
  5. <div id="fb-root"></div>
  6. <script>(function (d, s, id) {
  7. var js, fjs = d.getElementsByTagName(s)[0];
  8. if (d.getElementById(id)) return;
  9. js = d.createElement(s); js.id = id;
  10. js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
  11. fjs.parentNode.insertBefore(js, fjs);
  12. }
  13. (document, 'script', 'facebook-jssdk'));
  14. </script>
  15. </head>
  16. <body>
  17. <div class="fb-like" data-href="https://www.c-sharpcorner.com" data-width="500" data-layout="standard" data-action="like" data-show-faces="true" data-share="true"></div>
  18. </body>
  19. </html>

Now see the output:

Like comment

Send Message