4

I have a facebook likebox on my site (not an iframe app) where I need to create gated content. I understand the FB.Event.subscribe using edge.create and edge.remove but what I really need is to know if a user already likes the page not simply if they became a fan or stopped being a fan. Is there anything I can see as a callback maybe from the xfbml.render?

I am limited (by my company) to using front end languages, meaning javascript is really my only option at this point. I would gladly use the "signed_request" option but best I can tell that seems to be only accessible via server side languages.

Is there any way for me to determine whether someone already "Likes" a page using only javascript?

Jacob
  • 41
  • 1
  • 2

2 Answers2

6

Yes, you can do this completely in javascript using the FB Javascript sdk.

function RunLikeCheck() {
var likeId = 'yourLikeIdHere';
    FB.api({
        method: 'fql.query',
        query: 'SELECT uid FROM page_fan WHERE page_id = ' + likeId + ' AND uid = me()'
    },
                function (response) {

                    if (response.length == 1) {
                        $("#HasLiked").val('true');
                        $('#frmAllow').submit();
                    }
                    else {
                        $("#HasLiked").val('false');
                        $('#frmAllow').submit();
                    }
                }
            );
}

Now this is assuming that you already have the user logged in and have the correct permissions.

Joey Schluchter
  • 2,522
  • 3
  • 22
  • 26
  • 1
    This is the only answer I've found where someone isnt logging in through your app. Thanks! Used this on a page tab and it worked great. Note that when using it for a tab use the page id, not the app id. – Nate914375 Feb 21 '14 at 00:11
0

Here is some additional sample javascript code for implementing a like gate that does not require the FB.api call (but does require the user to re-like every time they visit the page).

http://linksy.me/viral-gate

Adam Loving
  • 443
  • 5
  • 12