使用FQL仅从Facebook API检索即将到来的生日 [英] Using FQL to retrieve only upcoming birthdays from Facebook API

查看:80
本文介绍了使用FQL仅从Facebook API检索即将到来的生日的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用关于FQL的信息

Using the information on FQL and the user table from Facebook's Developer's docs, I've come up with the following code.

    //build fql string
    $fql = "SELECT name, birthday_date FROM user 
              WHERE uid IN
                (SELECT uid2 FROM friend WHERE uid1 = me())
              AND strlen(birthday_date) != 0 AND substr(birthday_date,0,3) 
            IN ('{$currentMonth}/', '{$nextMonth}/')";
    $fql.=$orderBy;
    $fql.=" LIMIT " . $limit;

    //query facebook
    $params  =   array(
                 'method'    => 'fql.query',       
                 'query'     => $fql,
                 'callback'  => ''     
                  );
    $birthdays  =  $this->facebook_obj->api($params);

$currentMonth$nextMonth分别以mm格式设置为当前月份和下个月的字符串表示形式. (例如"09","10"等)

$currentMonth and $nextMonth are set to string representations of the current month and next month respectively, in mm format. (eg "09", "10" etc.)

这是有效的",但可以说今天是11月29日,我有20个朋友的生日是11月,而$limit设置为10.在这种情况下,很有可能是10个生日退货将全部在11月29日之前.

This is "working", but let's say that today is November 29th, I have 20 friends with birthday's in November and $limit is set to 10. In this case, there is a very good chance that the 10 birthdays it returns will all be before November 29th.

我真正想做的是从今天开始的这个月和下一个生日.我该如何修改此查询以完成此操作?

What I would really like to do is get upcoming birthdays from today's day out, for this month and next. How could I modify this query to accomplish that?

谢谢!

* * 编辑,有关可能的替代解决方案,请参见Shawn和I之间的注释线程.尚未接受任何答案,因为没有答案可以直接解决原始代码/问题.

** Edit, see comment thread between Shawn and I for possible alternative solutions. No answer accepted yet as none directly addresses original code / question.

推荐答案

这已经推迟了几个月,但也许可以帮助其他面临相同问题的人.基本上,FQL IN运算符不检查该值是否在给定范围内,而是检查给定值是否与所提供的任何不同值匹配.在您的示例中,如果值"09"和"10",则返回9月和10月的所有生日,因为这些生日月份与提供的月份数匹配.

This is some months late but maybe helps other people facing the same problem. Basically, the FQL IN operator does not check whether the value is in a given range, but whether the given value matches any of the distinct values that are provided. In your example if '09' and '10' are the values, then all birthdays in September and October are returned since those birthday months match the provided month numbers.

您可以做的是使用PHP或您使用的任何其他语言计算以下值,并在FQL中使用它们(今天是3月17日,并说我们希望4月17日是结束日期):

What you can do is calculate the following values using PHP or whatever other language you are using and use them in your FQL (today is 17 March and say we want 17 April is end date):

  • 当月的今天(17),
  • 一年中的今天的月份(03)
  • 一天的结束日期(17)
  • 一年中的结束日期月份(04)

确保分别使用dd和MM格式化日期和月份(如果是一位数字,则用零填充).然后,您的FQL将如下所示:

Make sure days and months are formatted using dd and MM respectively (padded with zero in case of single digits). Then your FQL would look like this:

      SELECT name, birthday_date
      FROM user 
      WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me())
      AND strlen(birthday_date) != 0
      AND ((substr(birthday_date, 0, 2) = '03'
      AND substr(birthday_date, 3, 5) >= '17')
      OR (substr(birthday_date, 0, 2) = '04'
      AND substr(birthday_date, 3, 5) < '17'))
      ORDER BY birthday_date

这将返回生日在3月17日至4月17日之间的朋友.

This will then return the friends who's birthday falls between 17 March and 17 April.

这篇关于使用FQL仅从Facebook API检索即将到来的生日的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆