我正在编写一个应用程序,其中我使用 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";
但是我没有得到任何记录,我失踪了吗?
答案 0 :(得分: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();
}
答案 1 :(得分: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
强>