Facebook Like functionality using C# SDK
Asked Answered
S

2

17

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.

Salicin answered 25/9, 2018 at 10:6 Comment(10)
sounds super-spammy, why would people want to see a post on a page for every new like? anyway, what you want to achieve is not possible. as you found out already, edge.create is deprecated. you will never get the user_likes permissions approved for those kind of things, and that would be the only way - each user who liked your page would have to authorize your app for that as well.Arleyne
btw, that´s not jquery, that´s simple javascript. just saying ;)Arleyne
@luschn Okay, let's say User has logged in to the Facebook and gave permissions to our websiteSalicin
still, you would need to go through the review process. and facebook would definitely not approve it for something like that. you can try, of course.Arleyne
@luschn There are many websites implementing that like you can check followlike.comSalicin
"This Domain May Be For Sale" - nope ;)Arleyne
it's followlike.netSalicin
that page is highly illegal, they say they do not sell likes, but they also write the exact opposite: "Simply add your Link or Social Account. Offer a bid, then people will follow, like, view or share your content if they wish" - selling likes is not allowed. btw, they are not using an app for this, as it seems. it works completely different from what you are trying to achieve.Arleyne
It is not clear what you're asking. Please be more specific regarding your question.Elenaelenchus
In order to achive this goal you can use Webhooks. Please see: developers.facebook.com/docs/graph-api/webhooksNebulous
A
1

...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/

Arleyne answered 3/7, 2019 at 7:52 Comment(0)
N
0

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.

Nkrumah answered 14/10, 2018 at 10:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.