Facebook Login

Disclaimer: The code within the post is NOT ready for a production environment.  I have halfway pulled it out of Codeigniter and half formatted as you would need.  So this is not usable in a production environment. It is ONLY meant to serve as examples.

I had to write about this.  This was probably one of the most annoying things I have had to work with in a long time.  I have found a lot of people online who have had very similar problems with this. I want to try and hopefully save someone a lot of stress and heartache from having to try to figure out the Facebook registration and login by themselves.  I have had about 2-3 days worth of very aggravating trial and error. I figured out a few key points and thoroughly understand how this works, inside and out.

Step One: Create App

Create a facebook account (unless you already have one).  Once that is created, go into Facebook and login. At the very bottom of the page,
once you login, you will see a “Developers” link.  You have to go to the very bottom of the page.  Click that link.  At the top right hand corner of the screen, click “My Apps”. At the top right of this page click, “Set Up New App”.  Follow the instructions from there. It’s pretty simple. Just put in all of your information, and setup the return URL as your website address. This is VERY important. So if your website is http://www.letseatcheese.com, then that is what goes in your domain and URL settings.  This is a very important step. Make sure you follow the instructions on this part very carefully.

Also note..if you can’t get to the create app screen, then it might be because your Facebook account isn’t authorized. IF that is the case, Facebook would return an error about having to register your account (either using your mobile number, or your credit card).  Perform whatever steps are needed to verify that. Once you have all of that ready, your ready to go.

That’s it.  You have created the app. Inside the app settings please note your app information. You will need the APP Id, Secret Key, and API Key.  You will need to make note of all of these. They are very important, as is the site url and site domain.  90% of the time you have issues setting this up, it’s going to come down to some of that basic information being wrong.

Step Two: Registration

The first thing you have to do is setup a way for users to assign their user account (on your site) with a facebook system.  This is what allows the automatic login to occur from Facebook.  There has to be some type of communication initially between Facebook and your system in order to record the Facebook User ID.  This is what allows your system to match up user accounts during the login process.  To be honest with you, the entire registration process is very easy.

There are a variety of ways to set this up. However, I did not want to have to fight with some of the methods they present, so I used the more straight forward Iframe. It worked for me very well.  You would simply add the following code to your registration form. So you have your standard registration form (where they can register) and then you have your facebook Connect code.  This code allows for standard registration, along with setting up Facebook integration (so they can do facebook login).