我正在创建自己的应用程序来显示即将到来的朋友的生日。我有权从Facebook获取此日期,并且我在我的网站上显示我的所有朋友的出生日期。我唯一的问题是如何显示ie。前10个即将到来的生日?我正在使用$ facebook-> api('/ me / friends?limit = 10),但不知道如何对它们进行排序。有人帮吗?我应该尝试对哪些代码进行排序?一些facebook api代码或php代码。如果php那么也许你有一些提示如何做到这一点。欢呼!
答案 0 :(得分:3)
试试这个让它像你提到的那样工作:
$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);
这将在生日快乐中对朋友进行排序......现在您可以将此数据用于进一步的逻辑
答案 1 :(得分:2)
我自己解决了这个问题。非常简单的解决方案...也许太简单但完美无缺。那是我的代码。也许它有助于将来;)
$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是一个将facebook的月份数据转换为本地语言类型的数组。
欢呼和非常感谢^ Love Sharma给予帮助。啤酒给你;)