Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if user shared website (Facebook)? Is it possible?

I am currently writing a website and I need some help about facebook integration. I need a function (PHP or JS, both will help) that can check if a given user shared my website, and I couldn’t find out how to write one. Could you please point me at the right direction?

like image 769
Sagi Hatan Avatar asked Jun 21 '12 13:06

Sagi Hatan


People also ask

How do I verify the ownership of a domain on Facebook?

Upload an HTML file provided by Facebook to your web directory and confirm domain ownership in Business Manager. Add a meta tag to the <head> section of your domain home page If you are verifying a domain on behalf of a client (e.g. as an agency) please make sure that the domain is verified in the domain owner's Business Manager.

Where can I find more information about implementing the FB pages tag?

You can find more information about implementing the fb:pages tag in the Open Graph - Object Properties documentation.

How do I verify the HTML file of my website?

Download the HTML verification file. Upload the file to the root directory of your website. You will be able to see that it is uploading at the link provided in the HTML File Upload tab. Once it is done, click the Verify button at the bottom of the HTML File Verification tab for the selected domain.


1 Answers

First you have to load the Facebook SDK right after your tag:

<div id="fb-root"></div>
  <script>
  window.fbAsyncInit = function() {
    FB.init({
      appId                : "YOUR APP ID",
      status               : true, // check login status
      cookie               : true, // enable cookies to allow the server to access the session
      xfbml                : false,  // parse XFBML
      perms                : 'read_stream',
      access_token         : "USER ACCESS TOkEN",
      frictionlessRequests : true
    });
  };

  // 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/pt_BR/all.js";
    fjs.parentNode.insertBefore(js, fjs);
  }(document, 'script', 'facebook-jssdk'));

</script>

Then you can use the callback function to do what you want:

<script type="text/javascript">
    function shareOnFacebook() {
    FB.ui(
      {
        method        : 'feed',
        display       : 'iframe',
        name          : 'name',
        link          : 'http://www.linktoshare.com',
        picture       : 'http://www.linktoshare.com/images/imagethumbnail.png',
        caption       : 'txt caption',
        description   : 'txt description',
        access_token  : 'user access token'
      },
      function(response) {
        if (response && response.post_id) {

          // HERE YOU CAN DO WHAT YOU NEED
          alert('OK! User has published on Facebook.');

        } else {
          //alert('Post was not published.');
        }
      }
    );
  }
</script>

Then you should use it like this:

<a href="#" onclick="shareOnFacebook();">Share on facebook</a>
like image 83
Pedro Casado Avatar answered Sep 20 '22 07:09

Pedro Casado