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

感情迁移 提交于 2019-12-03 10:14:47

问题


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?


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/5340678/fan-gate-like-gate-show-to-connections-with-javascript-and-like-box

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!