简体   繁体   中英

Current Month Facebook Friends Birthdays in Android

I am writing an app in which i am fetching list of Facebook Friends using Hackbook Sample Code but now i want to fetch list of Facebook Friends those birthdays in Current Month , to get list of all Friends i am using this code:

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

Still i am using below code to get List of Friends those Birthdays in Current Month :

 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";

but i am not getting any record, where i am missing ?

What you can do is calculate the following values using language you are using and use them in your FQL:

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

Make sure days and months are formatted using dd and MM respectively (padded with zero in case of single digits). Then your FQL would look like this:

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

This will then return the friends who's birthday falls between 01 Jan and 31 Jan.

Update: Calculate current month and last date of current month:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM