Facebook 即将到来的生日仅在今年获取

问题描述 投票:0回答:1

我想获取从当前日期到明年当天的 Facebook 好友生日。 todate 是距现在 364 天后的日期(m/d)。为此,第一个 fql 是检索从 1 月到当前日期的数据,第二个 fql 是检索从当前日期到 12 月 31 日的数据。我想对接下来 11 个月零 29 天即将到来的生日应用分页。以下查询正在运行并获取数据。任何人都可以告诉我这样做的最佳方法。任何建议将受到高度赞赏。

$fromDate = date('m/d');
$past_birthdays = $facebook->api(array(
                'method' => 'fql.query',
                'query' => "SELECT uid, name, birthday, birthday_date,substr(birthday_date,0,3) FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me()) AND birthday_date<'$toDate' AND birthday_date>='01/01' order by birthday_date",
                'access_token' => $accessToken
                    ));
if ($toDate > $fromDate) {
            $condition = " AND birthday_date<'$toDate'";
        } else {
            $condition = "";
        }

$upcoming_birthdays = $facebook->api(array(
                'method' => 'fql.query',
                'query' => "SELECT uid, name, birthday, birthday_date,substr(birthday_date,0,3) FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me()) AND birthday_date>='$fromDate' $condition order by birthday_date",
                'access_token' => $accessToken
                    ));
php facebook-php-sdk facebook-fql multi-query
1个回答
1
投票

就像你的情况一样,我在 facebook api explorer 上检查过,如果你在查询中提供限制,那么它的输出不一致,解决你的问题的最好方法是加载整个生日 在数组中列出并在插槽中显示它。

$fromDate = date('m/d');
        $past_birthdays = "";
        $upcoming_birthdays = $facebook->api(array(
            'method' => 'fql.query',
            'query' => "SELECT uid, name, birthday, birthday_date, substr(birthday_date, 0,3) from user where uid in (select uid2 from friend where uid1=me()) and birthday_date >='$fromDate' order by birthday_date Limit 0,500",
            'access_token' => $accessToken
                ));
        $no = count($upcoming_birthdays); //exit;
        if ($no < 500) {
            $Limit2 = 500 - $no;
            $past_birthdays = $facebook->api(array(
                'method' => 'fql.query',
                'query' => "SELECT uid, name, birthday, birthday_date, substr(birthday_date, 0,3) from user where uid in (select uid2 from friend where uid1=me()) and birthday_date >='01/01' and birthday_date <= '$fromDate' order by birthday_date Limit 0,$Limit2",
                'access_token' => $accessToken
                    ));
            //echo count($past_birthdays);exit;
            $upcoming_birthdays = array_merge($upcoming_birthdays, $past_birthdays);

无需获取今天,因为您要获取全年。此代码仅获取 500 个,但运行全年查询。

© www.soinside.com 2019 - 2024. All rights reserved.