Facebook即将到来的生日只在今年获得

时间:2012-10-22 10:51:09

标签: facebook-fql facebook-php-sdk multi-query

我想从当前日期到明年当天获取Facebook朋友生日。 todate是364天后到m / d的日期。为此,首先fql将数据从jan检索到当前日期,第二个用于从当前日期获取数据到31 dec。我想在接下来的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
                    ));

1 个答案:

答案 0 :(得分: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);

没有必要采取todate,因为你拿整整年。这个ccode只获取500但运行查询整年。