2017-05-05 36 views
2

我遇到了有关Facebook Workplace的Account Management API的问题。我所要做的就是构建一个快速简便的员工目录,抓住我们所有的活跃用户,并吐出他们的名字,头衔,部门和照片。问题是,返回的数据似乎不符合上面链接中所示的Facebook核心架构。一些架构数据会回来,但从来没有照片,无论我怎么尝试。Facebook工作场所帐户管理API不返回照片

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; 
} 

哪还给:

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 '[email protected]' (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 

所以你可以看到,它返回等领域是“核心”架构的一部分,但缺少“照片”阵列等。我认为这可能是因为用户没有任何照片,但几乎所有人都有个人资料照片,许多人有更多。我试图获得他们的用户信息,但遇到同样的结果,没有照片。

有人试过类似的东西吗?非常感谢任何帮助,这对我们来说是一个障碍。

感谢

回答

1

获得简介信息,不使用SCIM,但图形API https://graph.facebook.com/community/members将列出所有成员

https://graph.facebook.com/[email]为您的会员将获得所有的相关信息之一。

之后,你必须设置你想得到的参数与字段参数。

在我们的实现,我们从这个请求得到整个数据

https://graph.facebook.com/XXXX/members?fields=email,picture.type(large),link,title,first_name,last_name,department,updated_time,managers {EMAIL} &上限= 500

+0

我的印象是我不能使用常规的图形API的工作场所下?我只需要我们所有员工的名单,包括他们的姓名,职位,电子邮件,照片,而不是深度信息。另一个问题是Graph API需要使用OAuth2进行更加严格的认证流程,每次都必须由某人授权,或者使用长期令牌3个月。 SCIM在实际请求中只需要一个密钥。 如果Graph可用于Workplace并且是唯一的方法,我会切换。但文件说,数据应该回来与SCIM,所以我宁愿这一点。 –

+0

此解决方案工作。我能够获得所有我想要的数据,而无需使用OAuth2。谢谢。 –

相关问题