Last active
August 29, 2015 14:28
-
-
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.
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
/* | |
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