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

前端 未结 2 639
野的像风
野的像风 2020-11-27 20:39

Is this scenario possible?

Customer goes to my website, wants to download a PDF technical document that interests them, they click the Download button and a Facebook

2条回答
  •  生来不讨喜
    2020-11-27 21:03

    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

    This file is locked, to unlock and download it, share it

    Download File

    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

提交回复
热议问题