problem getting the friends birthday with facebook api
here is the code , that supposed to retreive the birthday of my friends corresponding to today .
$friends = $facebook->api('me/friends');
$uids = "";
foreach($friends as $f) {
$uids .= "uid=$f OR ";
}
$query_uids = substr($uids,0,strlen($query_uids)-4);
date_default_timezone_set('UTC');
$current_date = date("m/d");
echo "<br />searching : $current_date<br />";
$data = $facebook->api(array('method'=>'fql.query','req_perms' => 'friends_birthday','query'=>"SELECT name, uid FROM user WHERE ( ($query_uids) AND strpos(birthday_date,'$current_date') >= 0 )") );
if(count($data) > 0) {
foreach($data as $d) {
print_r($d);
开发者_如何学Python }
} else {
echo "<br />No Birthdays Today<br />";
}
in my page i have another script to retrive user friends too above this one and its working properly , the result shown with this snippet issearching and WHITE SPACE !!!!
please help thanks
When you mean getting friends' birthdays corresponding to today - I'm assuming you want to find if any of your friends birthday is today or not.
1) First thing, you have to get today's date:
$today = date('m\/d');
2) Second using this date, we will run a query to select all your friends whose birthday is today
$data = $facebook->api(array(
'method' =>'fql.query',
'req_perms' => 'friends_birthday',
'query' => "select uid,name,birthday_date from user where uid in (select uid2 from friend where uid1=me()) and strpos(birthday_date,$today)>=0 ") );
3) Next you check the size of the data set, if it's ZERO - there are no birthdays today, else you loop through the dataset and print the friends name whose birthday is today.
if(count($data)==0)
{
echo 'No Friends Birthdays today';
}
else
{
echo 'Friends whose birthday is today';
foreach($data as $today_bday) {
echo $today_bday['name'];
}
}
If this is not what you are looking for - let me know.
精彩评论