Skip to content

Instantly share code, notes, and snippets.

@lukasborawski
Last active August 29, 2015 13:59
Show Gist options
  • Save lukasborawski/10828393 to your computer and use it in GitHub Desktop.
Save lukasborawski/10828393 to your computer and use it in GitHub Desktop.
Facebook competition accessibility from liking of profile.
(function(){
window.fbAsyncInit = function() {
FB.init({
appId : '8547685675671896', // App ID
// channelUrl : 'http(s)://yourdomain.com/channel.html', // Channel File
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
FB.login(function(response) {
if (response.status == 'connected') {
var user_id = response.authResponse.userID;
var page_id = "161456546118193";
var fql_query = "SELECT uid FROM page_fan WHERE page_id=" + page_id + " and uid=" + user_id;
var like_screen = $('.likeScreen'),
contest_screen = $('.contestScreen');
var keepGoing = true,
t;
function loop() {
FB.api('/me/likes/'+page_id, function(response) {
if (response.data[0]) {
like_screen.css('display','none');
contest_screen.fadeIn(300);
clearTimeout(t);
} else {
contest_screen.css('display','none');
like_screen.fadeIn(300);
}
});
if (keepGoing) {
setTimeout(loop, 1000);
}
}
function startLoop() {
loop();
}
startLoop();
} else {
// user is not logged in
}
});
};
}).call(this);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment