Created
January 30, 2013 18:26
-
-
Save dhigginbotham/4675453 to your computer and use it in GitHub Desktop.
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
/* | |
This handles the FBAsync login as well as the Authentication bit | |
*/ | |
var _s | |
, FacebookConnect = { | |
settings: { | |
status: null, | |
login: $('#facebook-auth'), | |
share: $('#facebook-share') | |
}, | |
init: function() { | |
_s = this.settings; | |
this.bindUILoginStatus(); | |
this.bindUIAppReq(); | |
}, | |
bindUILoginStatus: function() { | |
_s.login.live('click', function() { | |
FacebookConnect.getLoginStatus(); | |
}); | |
}, | |
bindUIAppReq: function() { | |
_s.share.live('click', function(){ | |
FacebookConnect.sendAppInviteRequest(); | |
}); | |
}, | |
getLoginStatus: function() { | |
FB.getLoginStatus(function(response) { | |
if (response.status === 'connected') { | |
// the user is logged in and has authenticated | |
_s.status = response.authResponse; | |
console.log('User is connected'); | |
} else if (response.status === 'not_authorized') { | |
console.log('User is not connected'); | |
// the user is logged in to Facebook, no authy | |
} else { | |
console.log('User is not logged into Facebook'); | |
// the user isn't logged in to Facebook. | |
} | |
}); | |
}, | |
sendAppInviteRequest: function(to) { | |
FB.ui({ | |
method: 'apprequests', | |
to: to, | |
message: 'You should learn more about this awesome site.', | |
data: 'tracking information for the user' | |
}); | |
return false; | |
}, | |
getUserInfo: function() { | |
FB.api('/me', function(resp) { | |
console.log(resp); | |
}); | |
}, | |
userLogin: function() { | |
FB.login(function(response) { | |
if (response.authResponse) { | |
console.log('Welcome! Fetching your information.... '); | |
FB.api('/me', function(response) { | |
console.log('Good to see you, ' + response.name + '.'); | |
}, {scope: 'email,user_likes'}); | |
} else { | |
console.log('User cancelled login or did not fully authorize.'); | |
} | |
}); | |
} | |
}; | |
/* | |
Share APP | |
*/ | |
//fireworks! | |
(function() { | |
FacebookConnect.init(); | |
// console.log(FB.getAccessToken()); | |
})(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment