Created
May 20, 2011 20:03
-
-
Save joesavak/983681 to your computer and use it in GitHub Desktop.
fbconnnect.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(function() { | |
window.fbAsyncInit = function() { | |
FB.init({appId: '132068066870042', status: true, cookie: true, | |
xfbml: true}); //dev | |
//FB.init({appId: '187884157925798', status: true, cookie: true, | |
// xfbml: true}); //prod | |
FB.getLoginStatus(function(response) { | |
if (response.session) { | |
// logged in and connected user, someone you know | |
$('#fbusing').show(); | |
//take this opportunity to update stuff (access token especially) | |
$.post('/users/savefbuid', { | |
'fbuid': response.session.uid, | |
'fbaccess': response.session.access_token | |
},function(data) { | |
}, "json"); | |
} else { | |
$("#connectwithfb").show(); | |
} | |
}); | |
}; | |
(function() { | |
var e = document.createElement('script'); e.async = true; | |
e.src = document.location.protocol + | |
'//connect.facebook.net/en_US/all.js'; | |
document.getElementById('fb-root').appendChild(e); | |
}()); | |
$('#fbconnect').click(function() { | |
FB.login(function(response) { | |
if (response.session) { | |
if (response.perms) { | |
$.post('/users/savefbuid', { | |
'fbuid': response.session.uid, | |
'fbaccess': response.session.access_token | |
},function(data) { | |
$('#fbuser').html("<a href=\"\" onclick=\"window.open('http://www.facebook.com/settings/?tab=privacy','_blank');return false;\"><font color=\"377FD1\">"+data.username+"</font></a>"); | |
$('#fbusing').show(); | |
$("#connectwithfb").hide(); | |
}, "json"); | |
} else { | |
// user is logged in, but did not grant any permissions | |
// eh - we shouldn't do anything here. | |
} | |
} else { | |
// user is not logged in | |
//user just closed the box. Don't need to do anything here. | |
} | |
}, {perms:'publish_stream'}); | |
}); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment