Wednesday, February 20, 2013

Show Upcoming Facebook Friends Birthdays

This query will grab a list of all the friends in the logged in users account:

SELECT uid, name, birthday_date FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1=me()) ORDER BY birthday_date ASC 

The pitfall of this is, you will need to check if the user has entered his/her birthday in their Facebook accounts.

A better query is (at least what I think is better):

SELECT uid, name, birthday_date FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1=me()) AND birthday_date >= '02/01' AND birthday_date <= '07/01' ORDER BY birthday_date ASC 

This one gets just the list of users who have filled in their birthday's in their Facebook accounts. And with the use of ORDER BY birthday_date, they will always be with the upcoming birthday at the top going all the way down to the last one in the result set.

The pitfall of this is, and feel free to test it, I have never once got the entire years worth of birthdays using the second query. SO in my application, I call in 6 months of data at a time. This has been always precise and pretty much, bang on.

I suspect, the second query will suit your purpose considering that you need to show the upcoming birthday at the top of the list. To ensure you always get the current date and month for a precise result at all times, use this example (and a simple Google search or SO search will give you more) to get the current date and month:

http://www.asbhtechsolutions.com/android-tutorials/android-get-current-date-and-time

Then, concatenate a String and pass that instance as the query.

NOTE: The month and the date used in the query need to be double digits at all times.

Source: http://facebook.stackoverflow.com/questions/14972171/show-upcoming-facebook-friends-birthdays

uc berkeley harrison barnes brett ratner stevie nicks anchorman capybara duggars

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.