3

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

Igor Milla
  • 2,767
  • 4
  • 36
  • 44
Nick Poulos
  • 449
  • 3
  • 19

1 Answers1

3

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

Sparrow
  • 2,548
  • 1
  • 24
  • 28
ogarbe
  • 46
  • 4
  • I was under the impression I could not use the regular Graph API for Workplace? I just need a list of all our employees including their name, title, email, photo, not deep profile info. The other issue was the Graph API requires a more strict authentication flow using OAuth2, which would have to be authorized by somebody each time, or 3-months using a long term token. SCIM only requires a key in the actual request. If Graph was available for Workplace and was the only way to do it, I would switch. But the docs say the data should be coming back with SCIM so I would prefer that. – Nick Poulos Jun 08 '17 at 14:08
  • This solution worked. I was able to get all of the data I wanted, without using OAuth2. Thank you. – Nick Poulos Jul 07 '17 at 16:29
  • Really works. All time before I was using scim and searched for picture - no success. Thanks a lot, man. – PokatilovArt Jun 19 '20 at 20:58