在 Facebook API 中按生日日期对我的好友列表进行排序?

发布于 2024-10-30 15:08:01 字数 249 浏览 2 评论 0原文

我正在创建自己的应用程序来显示即将到来的朋友的生日。我有权从 Facebook 获取这些日期,并且我会在我的网站上显示我所有朋友的出生日期。我唯一的问题是如何显示 ie。即将到来的前 10 个生日?我正在使用 $facebook->api('/me/friends?limit=10) 但不知道如何对它们进行排序。有人帮忙吗?我应该尝试使用哪些代码对它们进行排序?一些 facebook api 代码或 php 代码。如果是 php 那么也许你有一些如何做到这一点的技巧。干杯!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

仙女 2024-11-06 15:08:01

尝试这样做,使其像您提到的那样工作:

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

这将按生日对朋友进行排序...现在您可以使用此数据进行进一步的逻辑

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

九厘米的零° 2024-11-06 15:08:01

我已经自己解决了这个问题。非常简单的解决方案...也许太简单但效果完美。这是我的代码。也许它对将来的人有帮助;)

$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 的月份数据转换为本地语言类型。

欢呼并非常感谢^爱夏尔马给予的帮助。给你啤酒;)

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文