Created
July 23, 2014 11:14
-
-
Save Casperhr/6034150409df94630606 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public function ensureFbUser($fbAccessToken) { | |
| try { | |
| $fbUser = (new \Facebook\FacebookRequest( | |
| $session, 'GET', '/me?access_token=' . $fbAccessToken | |
| ))->execute()->getGraphObject(\Facebook\GraphUser::className())->asArray(); | |
| $user = $this->findByFbId($fbUser['id']); | |
| if(empty($user)) { | |
| $this->create(); | |
| $user = $this->save(array( | |
| 'fb_id' => $fbUser['id'], | |
| 'firstname' => $fbUser['first_name'], | |
| 'lastname' => $fbUser['last_name'], | |
| 'email' => isset($fbUser['email']) ? $fbUser['email'] : null, | |
| 'fb_town' => isset($fbUser['town']) ? $fbUser['town'] : null, | |
| )); | |
| } else { | |
| $user = $this->save(array( | |
| 'id' => $user[$this->alias]['id'], | |
| 'fb_id' => $fbUser['id'], | |
| 'firstname' => $fbUser['first_name'], | |
| 'lastname' => $fbUser['last_name'], | |
| 'email' => isset($fbUser['email']) ? $fbUser['email'] : null, | |
| 'fb_town' => isset($fbUser['location']->name) ? $fbUser['location']->name : null, | |
| )); | |
| } | |
| return $user; | |
| } catch(Exception $e) { | |
| return false; | |
| } | |
| } | |
| public function findFriendsFromFb($fbAccessToken) { | |
| try { | |
| $fbUsers = (new \Facebook\FacebookRequest( | |
| $session, 'GET', '/me/friends?limit=1000&access_token=' . $fbAccessToken | |
| ))->execute()->getGraphObject(\Facebook\GraphUser::className())->asArray(); | |
| $items = []; | |
| foreach ($fbUsers['data'] as $key => $value) { | |
| $item = $this->findByFbIdFriend($value->id); | |
| if(!empty($item)) { | |
| $items[] = $item; | |
| } | |
| } | |
| return $items; | |
| } catch(Exception $e) { | |
| return false; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment