Is it possible to add a link to download a file that can only be downloaded by sharing it on Facebook?

UPDATE

According to a Facebook new policy, this act is not allowed. Use it at your own risk. I hold no responsibilities for using this.

Yes, using the JavaScript SDK, it provides a response (it doesn’t anymore)
We will create an if statement to see if the response has a post_id if yes show the download link else do something else (alert the user, maybe?)

DEMO (API 2.0) (not working; revision required)

DEMO (API 2.7) working Rev#63

HTML

<div class="container">
    
    <div>
       <p>This file is locked, to unlock and download it, share it</p>
       <p class="hidden">Thanks for sharing, the file is unlocked and ready for download</p>
       <p class="hidden">In order to download this file, you need to share it</p>
    </div>

    <a class="fsl fsl-facebook" href="#" id="facebook-share">
       <span class="fa-facebook fa-icons fa-lg"></span>
       <span class="sc-label">Share on Facebook</span>
    </a>

    <a class="fsl content-download" href="#" id="download-file">
       <span class="fa-download fa-icons fa-lg"></span>
       <span class="sc-label">Download File</span>
    </a>
    
</div>

JavaScript (jQuery)

$('#ShareToDownload').on('click', function(e) {
            e.preventDefault();
            FB.ui({
                  display: 'popup',
                  method:  'share',
                  href:    location.href,
                  },
                  /** our callback **/
                  function(response) {
                          if (response && response.post_id) {
                          /** the user shared the content on their Facebook, go ahead and continue to download **/
                          $('#ShareToDownload').fadeOut(function(){ $('#downloadSection').fadeIn() });    
                          } else {
                          /** the cancelled the share process, do something, for example **/
                          alert('Please share this page to download this file'):
                  }
            });     
}); 

UPDATE

With the release of API version 2.0 the Feed dialog was deprecated and replaced with the new modern Share Dialog so the above code uses the new Share Dialog

Leave a Comment