Confirmation of facebook sharing with the API for WEB

0

I have a code in php with a facebook button, when clicking the person shares the content, however, on my site has a (regressive) counter, every time someone shares, it removes 1 from the counter. The button was generated and is functional, I would like to know if facebook returns the share confirmation by the API so I can cash in the counter ...

    
asked by anonymous 04.02.2017 / 21:08

1 answer

1

I found a solution, but it is not using the share button and yes the api, the response only fired 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 to Create a Facebook App, have a tutorial here

    
04.02.2017 / 22:09