Get Most Recent Employer using Facebook Graph API

Go To


How can I get the most recent employer for a logged in user using the Graph API? I know I can find all listed employers using:

And I can use the returned number from the 'id' field and tack on '/members' to get the members of that group.

Any help would be greatly appreciated.

2012-04-04 03:50
by FreeAsInBeer



$config = array(
'appId' => FB_APP_ID,
'secret' => FB_SECRET_KEY,
'cookie' => true // enable optional cookie support  
$facebook = new Facebook($config); 
$user = $facebook->getUser();

$params = array(
'scope' => 'user_work_history',
'redirect_uri' => FB_APP_URL,

$loginUrl = $facebook->getLoginUrl($params); 

if ($user) {
  try { 
    $user_profile = $facebook->api('/me');

    var_dump($user_profile["work"][0]["employer"]["name"]); //will display most recent eployer

  } catch (FacebookApiException $e) {
        $user = null;
    <script>top.location.href = "<?php echo $loginUrl?>";



2012-04-10 10:35
by Madan
Sorry Madan, this is for iOS, not PHP - FreeAsInBeer 2012-04-10 14:55


This functionality appears to be provided at user endpoint using additional parameters concordant with your search.

For example:

From the documentation:

  • work: A list of the user's work history
    • Permission tokens: user_work_history or friends_work_history
    • Returns: array of objects containing employer, location, position, start_date and end_date fields

You can reasonably find the user's current employer by inspecting the start_date and end_date respectively. For a different user than the current user, replace me with the desired PROFILE_ID.

2012-04-06 20:45
by MrGomez
I had thought about doing this, but I was wondering if there was a more automatic way. It just seemed like there should be a way to order the work history items by date on their end - FreeAsInBeer 2012-04-06 20:57
@FreeAsInBeer Agreed. This is the best way I can currently find according to their API, but if someone finds a better way, they're more than welcome to answer and grab the bounty. : - MrGomez 2012-04-06 20:58
No this is good. operating system independent to - Nicholas DiPiazza 2012-12-19 00:12