Getting Facebook User Info With PHP and Facebook Connect

Andy Stramer

Recently for a site I’ve been working on we wanted to have the ability to track a great deal of user activity without them having to go through a “Register User” process. Facebook Connect was a logical choice since almost everyone uses it now especially the target market for our site.  Facebook Connect is very easy to implement however most of the tutorials and beginners guides have you use javascript. If you just want a user to comment or do other simple actions, this works great but we needed more. That’s when I was pleasured to hear they have PHP library too!

require "library/facebook-platform/client/facebook.php";
$facebook = new Facebook("your app key", "your app secret");
$uid = $facebook->get_loggedin_user(); // will return users id if connected and logged in to your app*
$userDetails = $facebook->api_client->users_getInfo($uid, array ("last_name", "first_name", "name", "pic"));
$pic = $userDetails[0]["pic"];

The above will set the user’s Facebook Profile Pic to $pic. Making a class of my own out all these pulled details, I soon had everything I need easily at hand and I could integrate them right into our site almost right away.

I would suggest taking the time to adjust to the PHP library for anyone wanting to implement Facebook Connect. I feel it is much more versatile and you won’t have to rely on the fact your user has javascript enabled.

Last updated by on .

One thought on "Getting Facebook User Info With PHP and Facebook Connect"

  1. Carlos says:

    Thanks man!!

What Are Your Thoughts?

Your email address will not be published. Required fields are marked *