Step 2: Knowing When the Facebook Login Button Is Clicked
if (response.status == "connected")
// Perform appropriate action. This is where you collect user parameters and make an Ajax call.
// Here is how to get the parameters:
first_name = response.first_name;
last_name = response.last_name;
email = response.email;
location = response.location.name;
// Use the above values as parameters in the Ajax call to log-in or register this user.
// Perform appropriate action
Once these are triggered, a common approach is to make an appropriate Ajax call and perform some security and authentication steps on the server side. Notice in the above code to initially place the Facebook button, you use this line:
<fb:login-button show-faces="false" perms="user_about_me,email,user_location" autologoutlink="true" width="200" max-rows="1">
This is the code used to place the actual Facebook button within your HTML wherever you want the login button to appear. This is also the code to tell Facebook which permissions the user must consent to give your site upon logging in. The permissions or
perms field contains a few items. Upon login, the user will be presented with a dialog, asking them if your site can have access to that information.
If you try to get permissions to retrieve too many data points, it might spook some of your users and a portion of them may think twice about letting your site have access to so much of their information. If you want to increase adoption on your site, you should aim to request as few parameters as your application really needs. The code above gives you access to the person's name, email, and address in case you need to geo-encode their location. For most sites that is enough to perform basic authentication. If your site does not need to be location-aware, you can remove the