I am having an issue with the Account Management API for Facebook Workplace. All I am trying to do is build a quick and easy employee directory, that grabs all of our active users and spits out their name, title, dept, and photos. The problem is, the data coming back does not seem to match the Facebook Core Schema as seen in the link above. Some of the schema data comes back, but never photos, no matter what I seem to try.
private function getEmployees()
{
$done = false;
$current_index = 1;
$current_page = 1;
$results = [];
while(!$done) {
$res = $this->client->request(
'GET',
'https://www.facebook.com/company/XXXXXXXXX/scim/Users?count=100&startIndex=' . $current_index,
[
'headers' => ['Accept' => 'application/json',
'Content-Type' => 'application/json',
'Authorization' => 'Bearer ' . $this->token
]
]
);
$decoded = json_decode($res->getBody());
$total = $decoded->totalResults;
$perPage = $decoded->itemsPerPage;
if (isset($decoded->Resources)) {
$results = array_merge($results, $decoded->Resources);
if (($current_page * $perPage) >= $total) {
$done = true;
} else {
$current_page++;
$current_index += $perPage;
}
} else {
$done = true;
}
}
return $results;
}
Which gives back:
object(stdClass)[392]
public 'schemas' =>
array (size=3)
0 => string 'urn:scim:schemas:core:1.0' (length=25)
1 => string 'urn:scim:schemas:extension:enterprise:1.0' (length=41)
2 => string 'urn:scim:schemas:extension:facebook:starttermdates:1.0' (length=54)
public 'id' => int 10001156699923
public 'userName' => string 'np@lt.com' (length=21)
public 'name' =>
object(stdClass)[393]
public 'formatted' => string 'Nick P' (length=11)
public 'title' => string 'Lead PHP Engineer' (length=17)
public 'active' => boolean true
public 'phoneNumbers' =>
array (size=1)
0 =>
object(stdClass)[394]
public 'primary' => boolean true
public 'type' => string 'work' (length=4)
public 'value' => string '+1631123456' (length=12)
public 'addresses' =>
array (size=1)
0 =>
object(stdClass)[395]
public 'type' => string 'attributes' (length=10)
public 'formatted' => string 'Manhattan' (length=9)
public 'primary' => boolean true
public 'urn:scim:schemas:extension:enterprise:1.0' =>
object(stdClass)[396]
public 'department' => string 'IT' (length=2)
public 'manager' =>
object(stdClass)[397]
public 'managerId' => int 100011017901494
public 'urn:scim:schemas:extension:facebook:starttermdates:1.0' =>
object(stdClass)[398]
public 'startDate' => int 0
public 'termDate' => int 0
So as you can see, it returns other fields that are part of the 'core' schema, but is missing the 'photos' array and others. I thought this might have been because a user didnt have any photos, but almost all have profile pictures, and many have more. I tried getting their user information specifically but encountered the same result, no photos.
Anybody ever try something similar? Any help much appreciated, this has been a bit of a road block for us.
Thanks
To get profile information, don't use SCIM but graph API https://graph.facebook.com/community/members will list all members
and https://graph.facebook.com/[email] for one of your member will get all infos.
After that you have to set the params you want to get with the fields param.
In our implementation we get the whole data from this request
https://graph.facebook.com/XXXX/members?fields=email,picture.type(large),link,title,first_name,last_name,department,updated_time,managers{email}&limit=500