最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin4浏览0评论

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 pany) 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?

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 pany) 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?

Share Improve this question asked Mar 17, 2011 at 14:47 JacobJacob 411 silver badge2 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 6

Yes, you can do this pletely 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.

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

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论