Last active
October 4, 2017 22:12
-
-
Save guiliredu/2926483208299ba0b573a9626caf69d3 to your computer and use it in GitHub Desktop.
Facebook Login with Javascript
This file contains hidden or 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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Facebook Login with Javascript</title> | |
</head> | |
<body> | |
<div id="fb-root"></div> | |
<script> | |
window.fbAsyncInit = function() { | |
FB.init({ | |
appId : 'APPID', | |
cookie : true, | |
xfbml : true, | |
version : 'v2.10' | |
}); | |
FB.AppEvents.logPageView(); | |
}; | |
(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/sdk.js"; | |
fjs.parentNode.insertBefore(js, fjs); | |
}(document, 'script', 'facebook-jssdk')); | |
</script> | |
<button onclick="fbLogin();">Login with Facebook</button> | |
<script> | |
function fbLogin(){ | |
FB.login(function(response) { | |
if(response.status == 'connected'){ | |
FB.api('/me', { locale: 'en_US', fields: 'name, email' }, | |
function(response) { | |
console.log(response); | |
} | |
); | |
} | |
}, { scope:'email' }); | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment