Get Latest Employer Using Facebook Graph API
How can I get the latest employer for a registered user using the Graph API? I know I can find all the listed employers using:
https://graph.facebook.com/me/friendlists/work
And I can use the returned number from the "id" field and stick with "/ members" to get the members of that group.
Any help would be greatly appreciated.
source to share
<?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
}
? >
source to share
This functionality appears to be exposed to the user endpoint using additional parameters as appropriate for your search.
For example:
https://graph.facebook.com/me?fields=work
From the documentation :
-
work
: list of user's work history- Permission marks:
user_work_history
orfriends_work_history
- Returns: an array of objects containing the employer, location, position, start_date, and end_date fields
- Permission marks:
You can intelligently find the current user user by checking start_date
and end_date
accordingly. For a user other than the current user, replace me
with the required one PROFILE_ID
.
source to share