本月Facebook朋友生日在Android

我正在写一个应用程序,其中我使用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"; 

但我没有得到任何logging,我失踪了?

你可以做的是使用你正在使用的语言计算下列值,并在你的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分别格式化date和月份(在单个数字的情况下用零填充)。 那么你的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日之间返回生日的朋友。

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

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

使用此查询获取当前月份Facebook朋友按升序sorting

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