2

我正在编写一个应用程序,其中我正在使用Hackbook 示例代码获取 Facebook好友列表,但现在我想获取当前月份生日的 Facebook 好友列表,以获取我正在使用此代码的所有好友列表:

 public static void requestFriends(FacebookRequest facebookRequest) {
    Log.d(LOG_TAG, "requestFriends(" + ")");
    String query = "select name, birthday, uid, pic_square from user where uid in (select uid2 from friend where uid1=me()) order by birthday_date";
    Bundle params = new Bundle();
    params.putString("method", "fql.query");
    params.putString("query", query);
    FacebookUtility.asyncRunner.request(null, params, new FacebookRequestListener(FacebookRequestListener.FRIENDS, facebookRequest));
}

我仍然使用下面的代码来获取当月生日的朋友列表:

 Calendar c = Calendar.getInstance(); 
    int month = c.get(Calendar.MONTH)+ 1;

    String query = "select name, birthday, uid, pic_square from user where uid in " +
    "(select uid2 from friend where uid1=me())AND birthday_date >= '" + month + "/01' AND birthday_date <= '" + month + "/31' ORDER BY birthday_date ASC";

但我没有得到任何记录,我在哪里失踪?

4

2 回答 2

1

您可以做的是使用您正在使用的语言计算以下值并在您的 FQL 中使用它们:

1st's day of the current month (17),
Today's month of the year (01)
End date day of the current month (31)

确保分别使用 dd 和 MM 格式化日期和月份(如果是个位数,则用零填充)。然后您的 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, 2) = '01'
       AND substr(birthday_date, 3, 5) >= '01'
       AND substr(birthday_date, 3, 5) < '31'
  ) 
  ORDER BY birthday_date

然后,这将返回生日在 1 月 1 日到 1 月 31 日之间的朋友。

更新: 计算当前月份和当前月份的最后日期:

Calendar cal=Calendar.getInstance();
int currentmonth=cal.get(Calendar.MONTH)+1

public static Date getLastDateOfMonth(int year, int month) {
   Calendar calendar = new GregorianCalendar(year, month, Calendar.DAY_OF_MONTH);
   calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
   return calendar.getTime();
}
于 2013-01-17T07:54:32.463 回答
1

使用此查询以升序获取当前月份的 facebook 好友。

SELECT name, birthday, uid, pic_square FROM user WHERE uid in (SELECT uid2 FROM friend WHERE uid1=me())AND birthday_date >= '01/01/2013' AND birthday_date <= '31/01/2013' ORDER BY birthday_date

于 2013-01-22T16:03:33.193 回答