Skip to content

Instantly share code, notes, and snippets.

Created May 10, 2010 21:25
Show Gist options
  • 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
$(document).ready(function() {
// Logout link binding
$('#fb-logout').bind('click', function() {
FB.logout(function() {});
setTimeout(function() {
return false;
<div id="fb-root"></div>
window.fbAsyncInit = function() {
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
function(response) {
// Load the SDK Asynchronously
var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
if (d.getElementById(id)) {return;}
js = d.createElement('script'); = id; js.async = true;
js.src = "//";
ref.parentNode.insertBefore(js, ref);
<!-- Facebook Login button
<div id="fb-login" class="fb-login-button">Facebook</div>
<!-- Facebook Logout -->
<a id="fb-logout" href="#">
Logout</a> (Facebook)
Copy link

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