Pay with a tweet, Like or +1

Simple way to offer a download (or something else) when people either like your page on Facebook, tweet your link, or +1 on Google Plus. Be aware that any knowledgable code snoop could get around this pretty easily.

by Cam Gould

HTML

<div id="fb-root"></div>
<div id="restricted">
 
      // Add the default text of the tweet and your Twitter handle    
      <a href="https://twitter.com/share"                                       
          data-text="Pay with a tweet script" 
          data-via="camgould" class="twitter-share-button" data-lang="en"></a>
 
      // The URL of the page that visitor needs to +1 on Google Plus
      <g:plusone size="medium" callback="camgould"
          href="http://camgould.com/"></g:plusone>
 
      // The full URL of your Facebook Page goes here
      <fb:like href="http://facebook.com/camgould" send="false" 
          layout="button_count" width="220" show_faces="false">     
      </fb:like>
 
</div>

JavaScript

function holla() {
          // The file URL that visitors can download after their Like/tweet/+1
          var url = "http://www.camgould.com/free-thing-here";  
          url = "<a href='" + url + "'>Click here</a> to download the file.";
          document.getElementById("restricted").innerHTML = url;
        }
 
        window.fbAsyncInit = function() {
          FB.init({ status : true, cookie : true, xfbml  : true });
          FB.Event.subscribe('edge.create', function(response) { holla(); });
        };
 
        (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/all.js";
          fjs.parentNode.insertBefore(js, fjs);
        }(document, 'script', 'facebook-jssdk'));
 
        window.twttr = (function (d,s,id) {
          var t, js, fjs = d.getElementsByTagName(s)[0];
          if (d.getElementById(id)) return; js=d.createElement(s); js.id=id;
          js.src="//platform.twitter.com/widgets.js"; 
          fjs.parentNode.insertBefore(js, fjs);
          return window.twttr || (t = { _e: [], ready: function(f){ t._e.push(f) } });
        }(document, "script", "twitter-wjs"));
 
        twttr.ready(function (twttr) {
          twttr.events.bind('tweet', function(event) {
            holla();
          });
        });
 
        (function() {
          var po = document.createElement('script'); 
          po.type = 'text/javascript'; po.async = true;
          po.src = 'https://apis.google.com/js/plusone.js';
          var s = document.getElementsByTagName('script')[0]; 
          s.parentNode.insertBefore(po, s);
        })();