Android当前Facebook朋友生日
作者:互联网
我正在编写一个应用程序,其中我正在使用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
这将返回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();
}
标签:android,facebook,facebook-graph-api,facebook-fql,facebook-android-sdk 来源: https://codeday.me/bug/20190916/1807872.html