简体   繁体   中英

Facebook Like functionality using C# SDK

I want to display to know when the facebook like button is clicked and upon verify button click, I want to post the like to the fan page. I want to use Facebook C# SDK. Here is my code:

Html

<html>
<head>
  <title>Your Website Title</title>
    <!-- You can use open graph tags to customize link previews.
    Learn more: https://developers.facebook.com/docs/sharing/webmasters -->
  <meta property="og:url"           content="https://www.your-domain.com/your-page.html" />
  <meta property="og:type"          content="website" />
  <meta property="og:title"         content="Your Website Title" />
  <meta property="og:description"   content="Your description" />
  <meta property="og:image"         content="https://www.your-domain.com/path/image.jpg" />
</head>
<body>
  <button id="btnVerify">Verify</button>
  <!-- Load Facebook SDK for JavaScript -->
  <div id="fb-root"></div>
  <script>(function(d, s, id) {
    var js, fjs = d.getElementsByTagName(s)[0];
    if (d.getElementById(id)) return;
    js = d.createElement(s); js.id = id;
    js.src = "https://connect.facebook.net/en_US/sdk.js#xfbml=1&version=v3.0";
    fjs.parentNode.insertBefore(js, fjs);
  }(document, 'script', 'facebook-jssdk'));</script>

  <!-- Your like button code -->
  <div class="fb-like" 
    data-href="https://www.your-domain.com/your-page.html" 
    data-layout="standard" 
    data-action="like" 
    data-show-faces="true">
  </div>

</body>
</html>

Javascript

<script>
var liked_page = function() {
  alert("liked!");
}

FB.Event.subscribe('edge.create', liked_page);
</script>

Here I am using Javascript SDK but edge.create is depecreated. How to acheive the same using C# SDK. Please share your insights.

...upon verify button click, I want to post the like to the fan page

That´s done automatically with the Like Button. If you want to check if someone liked your Page right after using the Like Button, be aware that Like Gating is not allowed and the edge.create event is deprecated.

The only way to detect if a User (currently) likes your Page is to use the /me/likes endpoint of the Graph API with the user_likes permission. You have to go through Facebooks review process in order to use that permission, so make sure to read the platform policy first: https://developers.facebook.com/policy/

Facebook SDK for C# relies on GRAPH API, meaning it is here to help you use the GRAPH API much more easily.

You can find the documentation regarding likes in this Link :

You can get a list of pages the person liked but you cannot create likes (for example, pressing like).

Facebook removed this functionality so as of now, the only way to simulate like for the user is through facebook itself, meaning:

You will not be able to create the like functionality unless you redirect to facebook itself.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM