Sorting by birthday date my friend list in Facebook API?

本秂侑毒 提交于 2020-02-05 08:09:54

问题


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!


回答1:


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




回答2:


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



来源:https://stackoverflow.com/questions/5580128/sorting-by-birthday-date-my-friend-list-in-facebook-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!