Skip to content

Instantly share code, notes, and snippets.

@geschke
Created May 10, 2010 21:25
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 geschke/396572 to your computer and use it in GitHub Desktop.
Save geschke/396572 to your computer and use it in GitHub Desktop.
JavaScript example code for Facebook login with Django Middleware
<!-- slightly modified example of Facebook Connect with JavaScript SDK
Requirements: jQuery, Django Facebook Middleware (see https://gist.github.com/396557)
-->
$(document).ready(function() {
// Logout link binding
$('#fb-logout').bind('click', function() {
FB.logout(function() {});
setTimeout(function() {
window.location="/user/do_logout/";
},1000);
return false;
});
});
[...]
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : $('meta[property="fb:app_id"]').prop('content'), // App ID
channelUrl : 'CHANNEL_URL, see Facebook documentation',
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
FB.Event.subscribe('auth.login',
function(response) {
window.location.reload();
}
);
};
// Load the SDK Asynchronously
(function(d){
var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/de_DE/all.js";
ref.parentNode.insertBefore(js, ref);
}(document));
</script>
<!-- Facebook Login button
-->
<div id="fb-login" class="fb-login-button">Facebook</div>
<!-- Facebook Logout -->
<a id="fb-logout" href="#">
Logout</a> (Facebook)
@geschke
Copy link
Author

geschke commented Jul 15, 2012

This snippet is obsolete and doesn't work with the newer versions of Facebook API or Django middleware. I will create a new example soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment