Confirmation of sharing facebook with web API

Asked

Viewed 437 times

0

I have a php code with a facebook button, when clicking the person shares the content, however, on my site has a counter (regressive), every time someone shares, takes 1 of the counter. The button was generated and is functional, I wonder if facebook returns the confirmation of sharing by API for me to cash in counter...

  • What are you wearing? If you used the share button, it apparently doesn’t have https://developers.facebook.com/docs/plugins/share-button/, it even counts, but returns nothing(doesn’t have a callback function parameter)

1 answer

1


I found a solution, but it’s not using the share button, but rather the api, the only triggered Response when the user actually shares it

<div class="page-header">
  <h1>Share Dialog</h1>
</div>

<p>Click the button below to trigger a Share Dialog</p>

<div id="shareBtn" class="btn btn-success clearfix">Share</div>

<p style="margin-top: 50px">
  <hr />
  <a class="btn btn-small"  href="https://developers.facebook.com/docs/sharing/reference/share-dialog">Share Dialog Documentation</a>
</p>

<script>
document.getElementById('shareBtn').onclick = function() {
  FB.ui({
    method: 'share',
    display: 'popup',
    href: 'https://developers.facebook.com/docs/',
  }, function(response){


       if(response.post_id !== 'undefined'){
           alert('foi postado');
       }


  });
}
</script>

Here you can test the code Here you have more api info

Here is the load you need to put to use the facebook sdk

  // Load the SDK asynchronously
  (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 = "//connect.facebook.net/en_US/sdk.js";
    fjs.parentNode.insertBefore(js, fjs);
  }(document, 'script', 'facebook-jssdk'));

Still for the SDK you need Create a Facebook App, have a tutorial here

  • Thanks! It worked

Browser other questions tagged

You are not signed in. Login or sign up in order to post.