Maarten Provo
Maarten Provo

Reputation: 11

Reveal website-content when facebook-page liked

I'm trying to reveal content on my website only to people who like my facebook page. I've tried severall tutorials but none of them work. The closest I got was following this:

http://www.dejanlevec.com/2011/05/11/how-to-display-certain-page-content-only-to-users-who-have-liked-our-page-on-facebook/

I can get it to work if I first dislike the page and then like it on the facebook_test.php . Thus it doesn't detect if I already like the page.

Upvotes: 0

Views: 1188

Answers (2)

Skyler McCoy
Skyler McCoy

Reputation: 81

I have done this with javascript before using FB.Event.subscribe and edge.create as described below:

<script type="text/javascript"> 
  window.fbAsyncInit = function() {
    FB.init({appId: 'APP_ID_HERE', status: true, cookie: true, xfbml: true});
    FB.Event.subscribe('edge.create',
  function (response) {
     window.location = "http://redirectexamplehere.com";
  });
FB.Event.subscribe('edge.create',
function (response) {
  window.location = "http://redirectexamplehere.com";
});

  };
  (function() {
    var e = document.createElement('script');
    e.async = true;
    e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
    document.getElementById('fb-root').appendChild(e);
  }());
//]]>
</script>

This way a user will be redirected to wherever you specify upon them liking the page. Remember to load the SDK first or it won't work.

Upvotes: 1

Dustin Nielson
Dustin Nielson

Reputation: 1264

Detecting if a user likes you on a website is a bit trickier than in a Facebook page. You'll need to setup a Facebook application and use that on your website and have the user authenticate using the app in addition to liking your page. Once you have that connection with the user you can test to see if they are logged in and have liked your page. At that point you can display different types of content.

The extra step of having to authenticate the user is probably why you don't see this implemented on too many websites.

Upvotes: 0

Related Questions