cialis online pharmacy generic xenical cheap cialis online cialis generic viagra online in canada buy cheap levitra online cialis without a perscription order viagra uk no prescription flagyl cheap generic levitra buying viagra in the uk cheap viagra approved cialis deltasone online buy viagra online without prescription non prescription cialis buy orlistat uk buy cialis in india prednisone 60 mg female viagra online buy viagra without prescription celebrex prescriptions buy cialis canada best prices viagra alternative to prednisone cheapest generic levitra levitra 5mg cheap viagra cialis on line buy xenical without prescription online accutane canadian health care prednisone no prescreption viagra online generic female viagra europe buy cialis low price cheap india viagra

Client-Side Facebook App Login/Authorization

Here’s a nice JavaScript snippet that I’m certain quite a number of Facebook app developers might find useful. The script’s been around for a while, and has been last updated for about a year already. Nonetheless, it has been quite a popular snippet not to be re-shared. It’s originally shared by Brandon from GuineaCode and what it does is that lets you create a complete HTML page for your [Facebook] app that does the login process entirely on the client side.

Here are the steps you need to do to get it done.

  • Create a Facebook application (see Facebook developer docs.).
  • Because of a Facebook bug the app should have Sandbox Mode disabled (App Settings > Advanced > Authentication).
  • Uncomment the appropriate redirectUrl var.
  • Update the appId and redirectUrl vars with your Facebook app values.
  • Make the page available from a server.
 Thanks to
 for the FB.getLoginStatus example that allows all the Facebook
 authorization to be done client-side.
 <meta charset="utf-8" />
 <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
 <!--[if IE]><![endif]-->
 <script type="text/javascript" src=""></script>
 <div id="fb-root"></div>
 <script type="text/javascript">
 var appId = YOUR_APP_ID;
 // If logging in as a Facebook canvas application use this URL.
 //var redirectUrl = "";
 // If logging in as a website do this. Be sure to add the host to your application's App Domain list. 
 //var redirectUrl = window.location.href;
 // If the user did not grant the app authorization go ahead and
 // tell them that. Stop code execution.
 if (0 <= window.location.href.indexOf ("error_reason"))
 $(document.body).append ("<p>Authorization denied!</p>");
 // When the Facebook SDK script has finished loading init the
 // SDK and then get the login status of the user. The status is
 // reported in the handler.
 window.fbAsyncInit = function(){
 appId : appId,
 status : true,
 cookie : true,
 oauth : true
 // Sandbox Mode must be disabled in the application's settings
 // otherwise the callback will never be invoked. Monitoring network
 // traffic will show an error message in the response. Change the
 // Sandbox Mode setting in: App Settings - Advanced - Authentication.
 FB.getLoginStatus (onCheckLoginStatus);
 // Loads the Facebook SDK script.
 var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
 js = d.createElement('script'); = id; js.async = true;
 js.src = "//";
 // Handles the response from getting the user's login status.
 // If the user is logged in and the app is authorized go ahead
 // and start running the application. If they are not logged in
 // then redirect to the auth dialog.
 function onCheckLoginStatus (response)
 if (response.status != "connected")
 top.location.href = "" + appId + "&redirect_uri=" + encodeURIComponent (redirectUrl) + "&scope=user_photos,friends_photos";
 // Start the application (this is just demo code)!
 $(document.body).append ("<p>Authorized!</p>");
 FB.api('/me', function (response) {
 $(document.body).append ("<pre>" + JSON.stringify (response, null, "\t") + "</pre>");

Related Posts

Adding Instagram Badges to Your WordPress Profile

How to Create a Custom WordPress Registration Form with Flat UI

How to Create A Basic Hipster-Style Layout

How to Style Nav Links Using Floats With HTML5 and CSS3

1 Comment

  1. Abdul Qoyyuum


    Does this mean that they can login to my membership site with their Facebook account with this Javascript? That’s interesting. I always thought we need to use Python or something to get the Facebook’s API to work.

    Does this also mean that after they successfully login to my membership site with Facebook, will I get their little contact details? Like emails, phone numbers and their country? i.e. of course, with their permission.