Skip to content

Instantly share code, notes, and snippets.

@geschke

geschke/gist:396572

Created May 10, 2010
Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

@geschke 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