Reputation: 8186
I am looking for the least resource intensive way of getting all friends' birthday information by a given user object Id. Probably using Event Object since birthdays of friends are visible inside events.
Upvotes: 2
Views: 7835
Reputation: 2618
I've done something similar in the following way:
1) Like Awais pointed out - you need to first get the extended permission from the user at the time of login to access their birthday information
<fb:login-button perm="user_birthday, friends_birthday"></fb:login-button>
2) There are different ways of doing this, but if you are not using php sdk, you can get the friends birthday as follows
all_friends_profile = json_decode(file_get_contents('https://api.facebook.com/method/fql.query?query=select+uid,name,birthday_date+from+user+where+uid+in+(select+uid2+from+friend+where+uid1%3Dme())&format=json&access_token=...')); foreach($all_friends_profile as $profile) { echo $profile->name.' birthay='.$profile->birthday_date; }
Just replace the access token in the above code and it should loop through all your friends and print their birthdays
3) Basically the query I have used is
select uid,name,birthday_date from user where uid in (select uid2 from friend where uid1=me())
Good luck
Upvotes: 6
Reputation: 18006
quite easy.Just take extended permission of user birthday then just query user table to get birtday
<fb:login-button perm="user_birthday, friends_birthday"></fb:login-button> $user=json_decode(file_get_contents('https://graph.facebook.com/me/friends?access_token='.$cookie['access_token'])); foreach($user[data] as $friend) { $fql = "select name, birthday_date from user where uid=".$friend['id']; $param = array( 'method' => 'fql.query', 'query' => $fql, 'callback' => '' ); $fqlResult = $facebook->api($param); print_r($fqlResult);
Hope it will work
Upvotes: 0