Skip to content

Instantly share code, notes, and snippets.

@seansu4you87
Last active December 19, 2015 15:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seansu4you87/5980275 to your computer and use it in GitHub Desktop.
Save seansu4you87/5980275 to your computer and use it in GitHub Desktop.
JS Facebook Connect
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
// init the FB JS SDK
FB.init({
appId : 'YOUR_APP_ID', // App ID from the app dashboard
channelUrl : '//localhost:9000/channel.html', // Channel file for x-domain comms
status : true, // Check Facebook Login status
xfbml : true // Look for social plugins on the page
});
$(function() {
FB.getLoginStatus(function(response) {
if (response.status == 'connected') {
getCurrentUserInfo(response)
} else {
FB.login(function(response) {
if (response.authResponse){
getCurrentUserInfo(response)
} else {
console.log('Auth cancelled.')
}
}, {scope: 'email'});
}
});
function getCurrentUserInfo() {
FB.api('/me', function(userInfo) {
console.log(userInfo);
console.log(userInfo.name + ': ' + userInfo.email);
});
}
});
};
// Load the SDK asynchronously
(function(d, s, id){
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/all.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment