开发者

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!


Try This to make it work like you mentioned:

$friends = json_decode($facebook->api('/me/friends?fields=birthday'));
$friends_birth = array();
foreach($friends->data as $value){
  if(isset($value->birthday->)){
    $dt = split("/",$value->birthday);
    $friends_birth[$value->id] = mktime(0,0,0,$dt[0],$dt[1], date("y"));
  }
}
asort($friends_birth);
echo print_r($friends_birth);

This will sort friends in birthday wise... now you can use this data for further logic


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜