Beispiel #1
0
 public function getGroup()
 {
     if (is_null($this->group)) {
         $path = '/' . $this->id . '?fields=id,name,icon';
         $result = $this->request($path);
         $json_result = json_decode($result, true);
         $mapping = ['id' => 'id', 'name' => 'name', 'picture' => 'icon'];
         $this->group = Group::create($mapping, $json_result);
         $this->group->picture = $json_result['icon'];
         $this->group->link = 'https://www.facebook.com/groups/' . $json_result['id'];
         $this->group->can_post = true;
         $this->group->provider = static::$provider;
         $this->group->raw_response = $result;
     }
     return $this->group;
 }
Beispiel #2
0
 public function getGroups()
 {
     $path = '/people/~/group-memberships:(group:(id,name,site-group-url,small-logo-url,num-members,relation-to-viewer))?&format=json&count=999';
     $response = $this->request($path);
     $groups = json_decode($response, true);
     $group_pages = [];
     $mapping = ['id' => 'id', 'name' => 'name', 'picture' => 'smallLogoUrl', 'link' => 'siteGroupUrl'];
     // Make the page IDs available as the array keys and get their picture
     if (!empty($groups['values'])) {
         foreach ($groups['values'] as $group) {
             $group_pages[$group['_key']] = Group::create($mapping, $group['group']);
             $group_pages[$group['_key']]->provider = static::$provider;
             $group_pages[$group['_key']]->raw_response = $response;
             // Let's check if our user can post to this group.
             // Thank you for this wonder, LinkedIn! It's so fun parsing infinitely nested arrays...
             $actions = $group['group']['relationToViewer']['availableActions']['values'];
             array_walk($actions, function ($value) use($group, $group_pages) {
                 if ($value['code'] === 'add-post') {
                     $group_pages[$group['_key']]->can_post = true;
                 }
             });
         }
     }
     return $group_pages;
 }
Beispiel #3
0
 public function getGroups()
 {
     $profile = $this->getProfile();
     $path = '/' . $profile->id . '/groups?fields=id,name,icon';
     $result = $this->request($path);
     $json_result = json_decode($result, true);
     $groups = [];
     $mapping = ['id' => 'id', 'name' => 'name', 'picture' => 'icon'];
     // Make the group IDs available as the array keys
     if (!empty($json_result['data'])) {
         foreach ($json_result['data'] as $group) {
             $groups[$group['id']] = Group::create($mapping, $group);
             $groups[$group['id']]->picture = $group['icon'];
             $groups[$group['id']]->link = 'https://www.facebook.com/groups/' . $group['id'];
             $groups[$group['id']]->can_post = true;
             $groups[$group['id']]->provider = static::$provider;
             $groups[$group['id']]->raw_response = $result;
         }
     }
     return $groups;
 }