Facebook API Apps – Get Your User’s Info

| Posted by watashii | Filed under Programming, Web

When developing facebook applications, you generally would like to obtain some basic information about a user.  To do this, we use the facebook API function Users.getStandardInfo.  See first lesson for an introduction to creating facebook applications.  Note, this will only work if the user has granted your application to access their information.


Your facebook application, php hosted, would have authenticated with an api and secret key.  The id of the user using your application would also have been obtained as follows:

$appapikey = '<your_api_key_here>';
$appsecret = '<your_secret_key_here>';
$facebook = new Facebook($appapikey, $appsecret);
$user_id = $facebook->require_login();

Passing this user_id, and a list of details we want facebook to return back to us (inside an array), we now can use the getStandardInfo api call to retreive their details:

$user_details=$facebook->api_client->users_getStandardInfo($user_id, array('uid','last_name','first_name','name','sex','birthday','timezone','locale','affiliations'));

Thereafter, the results are fetched within an associative array:

print $user_details[0]['uid'];
print $user_details[0]['first_name'];
print $user_details[0]['last_name'];
print $user_details[0]['name';
...

And so forth… You can also use this api call over an array of user id’s, to grab details of multiple users at one go.

Share:

  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Print
  • email

Related Posts:

  1. Make Your First Facebook Application in 10 Minutes

Tags: , ,

5 Responses to “Facebook API Apps – Get Your User’s Info”

  1. Rathees Says:
    December 14th, 2009 at 4:55 am

    can i get the email as well from facebook api client?

  2. shay Says:
    August 17th, 2010 at 7:01 am

    cool thanks.

    I have database full of users Ids (100 of them) how can I pull user_info of all of those users at once.

    I am able to pull user info one by one, but I wanted to know how to do it at once.

    just email me thanks

  3. watashii Says:
    August 22nd, 2010 at 11:17 am

    You can pass the first argument of the users_getStandardInfo(…) call as an array, instead of a single user value. Then loop over the $user_details array to retrieve each user’s details.

  4. gopster Says:
    August 25th, 2010 at 5:36 pm

    HI there,

    if you can get blogs & websites to display live status, comments, photos and all of these.

    how do i get a blog or website to display the name of the current logged in user on facebook.

    for example

    i’ve logged into http://www.blog.watashii.com, and this website has a header displaying
    ” welcome ”

    any idea how this trick can be done?

  5. Julien Says:
    October 20th, 2010 at 1:31 pm

    Hi, thanks for this post.

    I would like to know how you find who are the used who granted your app ?

    Is there a way to retrieve the list of the users who granted the app ?

Leave a Reply