Skip to content

Instantly share code, notes, and snippets.

@bsimser
Last active August 29, 2015 14:28
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 bsimser/706458af24d8aaf06f88 to your computer and use it in GitHub Desktop.
Save bsimser/706458af24d8aaf06f88 to your computer and use it in GitHub Desktop.
The bare minimum JavaScript code needed to get a Facebook app up and running with an authorization prompt. User token is saved to a cookie for retrieval by server side code.
/*
complete facebook sdk authorization/login in 20 lines (or less)
include https://connect.facebook.net/en_US/sdk.js in your html page
*/
function onLogin(response) {
if(response.status === "not_authorized") {
// send the user somewhere as they refused to authorize your app
}
}
function onStatusChange(response) {
if(response.status === "not_authorized") {
FB.login(onLogin);
}
}
$(document).ready(function () {
FB.init({
appId: 'YOUR_APP_ID',
cookie: true, // save a cookie for the session so we can get it on the server side
status: true, // retrieve the status on each page load so we don't have to call getLoginStatus ourselves
version: 'v2.4'
});
FB.Event.subscribe('auth.statusChange', onStatusChange);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment