Created
March 5, 2012 17:39
-
-
Save timnovinger/1979729 to your computer and use it in GitHub Desktop.
Colorjar: Facebook JavaScript SDK for login and the PHP SDK for personalization
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
<?php | |
define('YOUR_APP_ID', 'YOUR APP ID'); | |
//uses the PHP SDK. Download from https://github.com/facebook/php-sdk | |
require 'facebook.php'; | |
$facebook = new Facebook(array( | |
'appId' => YOUR_APP_ID, | |
'secret' => 'YOUR APP SECRET', | |
)); | |
$userId = $facebook->getUser(); | |
?> | |
<html> | |
<body> | |
<?php if ($userId) { | |
$userInfo = $facebook->api('/' + $userId); ?> | |
Welcome <?= $userInfo['name'] ?> | |
<?php } else { ?> | |
<div id="fb-root"></div> | |
<fb:login-button></fb:login-button> | |
<?php } ?> | |
<script> | |
window.fbAsyncInit = function() { | |
FB.init({ | |
appId : '<?= YOUR_APP_ID ?>', | |
status : true, | |
cookie : true, | |
xfbml : true, | |
oauth : true, | |
}); | |
FB.Event.subscribe('auth.login', function(response) { | |
window.location.reload(); | |
}); | |
}; | |
(function(d){ | |
var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;} | |
js = d.createElement('script'); js.id = id; js.async = true; | |
js.src = "//connect.facebook.net/en_US/all.js"; | |
d.getElementsByTagName('head')[0].appendChild(js); | |
}(document)); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment