Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
fbconnnect.js
$(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
You can’t perform that action at this time.