Search code examples
facebookapisortingfriend

Sorting by birthday date my friend list in Facebook API?


I'm creating my own application to show forthcoming friend's birthday. I have a permission to get this dates from facebook and i'm displaying all my friends with their date of birth on my site. My only question is how to display ie. first 10 forthcoming birthdays? i'm using $facebook->api('/me/friends?limit=10) but have not idea how to sort them. Anyone help? Which code should i try to sort them? some facebook api code or php code. if php then maybe you have some tips how to do this.Cheers!


Solution

  • i've resolve the problem by myself. quite simple solutions... maybe too simple but works perfect. That's my code. maybe it help someone in future ;)

    $fql_n    = "SELECT uid, name, birthday_date FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me()) AND strlen(birthday_date) != 0 ORDER BY birthday_date";
    
        $parame  =   array(
               'method'     => 'fql.query',
                'query'     => $fql_n,
              'callback'    => ''
        );
        $fqlResultt   =   $facebook->api($parame);
        $ile_dat = 0;
    
        $miesiace_slownie = array("01" => "jan", "02" => "feb", "03" => "mar", "04" => "apr", "05" => "may", "06" => "jun", "07" => "jul", "08" => "aug", "09" => "sep", "10" => "oct", "11" => "nov", "12" => "dec");
        if($fqlResultt){
            foreach($fqlResultt as $ress){
                $data = date("m/d");
                list($fb_m,$fb_d) = explode("/", $ress['birthday_date']);
                $fb_date = $fb_m."/".$fb_d;
                if($data<=$fb_date) { ?>
                    <div class="fb_birthday_fr">
                        <span class="fb_brt_day"><?php echo $fb_d . ' ' . $miesiace_slownie[$fb_m]; ?></span>
                        <span class="fb_brt_fr"><?php echo $ress['name']; ?></span>
                    </div>
                    <?php
                    $ile_dat++;
                    if($ile_dat == 6) break;
                }
    
    
            }
        }
    

    $miesiace_slownie is a array that's convert month data from facebook into local language type.

    cheers and many thanks ^Love Sharma for given help. Beer for you ;)