CodeIgniter has great documentation, and a great community, and so whenever I need to figure something out, usually someone else has had the same question as me, and someone else has already answered it.
Not so with my recent problem. I wanted to use Facebook Connect, including Facebook's Graph API on an existing site I had already built last year using CodeIgniter. I tried to figure it out myself, gave up after a couple of days, and started looking to see if someone else had a solution. I found a Facebook library for CodeIgniter written by Elliot Haughin. But I kept getting error messages when sessions expired, and even when I wasn't getting error messages, I could only do half of what I needed the solution to do.
Oh, by the way, here's what I needed the solution to do:
- Let people log in to my site using their existing Facebook credentials
- Get the users name and photo from Facebook
- Get a list of their friends, including names and photos.
I was able to get logging-in working with Elliot Haughin's library, but I couldn't figure out how to get a user's friends' names and photos. And I didn't want to figure out the error messages I was getting.
Don't get me wrong. I don't mean to talk ill of Elliot Haughin. Looking at his site, it's obvious to me that the guy is smarter than me. It's just that I couldn't get his solution to work for my site.
After giving up on Elliot's library, I went back to trying what I was doing before. Eventually I got it working correctly. And since, as far as I know, there aren't any other tutorials explaining how to do it the way I did, I decided to write this tutorial to give back to the CodeIgniter community that has helped me out so well over the past 18 months or so.
I'll try to make this easy enough for someone as dumb as me to understand. If you are following along with this tutorial, I'm assuming you already can do the following:
- Understand PHP and HTML
- Understand how to build a site with CodeIgniter
- You kind of have an idea what MVC means and why you'd want to use it.