我写这封信,我正在使用取样品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";
但我没有得到任何记录,我在哪里丢失的?
你可以做的是计算使用的语言你正在使用,并在您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
那么这将返回谁是朋友的生日在01一月和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();
}
使用此查询来获取升序当前月的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