Jacob
Jacob

Reputation: 41

Fan-Gate, Like-Gate, show-to-connections, with javascript and like box?

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?

Upvotes: 4

Views: 5310

Answers (2)

Adam Loving
Adam Loving

Reputation: 443

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

Upvotes: 0

Joey Schluchter
Joey Schluchter

Reputation: 2612

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.

Upvotes: 6

Related Questions