public static function getUserFacebookFriends(GameUsers $user) { if (!empty($user)) { $userId = $user->getUserId(); $fbId = $user->getFacebookId(); $oauthTOken = $user->getOauthToken(); if (!empty($userId) && !empty($fbId) && !empty($oauthTOken)) { $facebook = new Facebook(array('appId' => FB_APP_ID, 'secret' => FB_APP_SECRET, 'cookie' => true)); $facebook->setAccessToken($oauthTOken); try { $fbFriends = array(); $apiUrl = "/me/friends"; while (!empty($apiUrl)) { $result = $facebook->api($apiUrl); $apiUrl = null; if (!empty($result)) { $data = null; if (isset($result["data"])) { $data = $result["data"]; } if (!empty($data) && sizeof($data)) { foreach ($data as $fbFriend) { if (!empty($fbFriend)) { array_push($fbFriends, $fbFriend); } } } unset($data); if (isset($result["paging"])) { $paging = $result["paging"]; if (!empty($paging) && isset($paging["next"]) && !empty($paging["next"])) { $next = $paging["next"]; if (strpos($next, "/friends")) { $apiUrl = "/me" . substr($next, strpos($next, "/friends")); } unset($next); } unset($paging); } } unset($result); unset($apiUrl); } return $fbFriends; } catch (Exception $exc) { error_log("FriendUtils>getUserFacebookFriends> Error : " . $exc->getMessage() . " Trace : " . $exc->getTraceAsString()); } } } return null; }