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:
https://graph.facebook.com/me/friendlists/work
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.
<?php
$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;
}
}
else
{
?>
<script>top.location.href = "<?php echo $loginUrl?>";
<?php
}
?>
This functionality appears to be provided at user endpoint using additional parameters concordant with your search.
For example:
https://graph.facebook.com/me?fields=work
From the documentation:
work
: A list of the user's work history
user_work_history
or friends_work_history
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
.