Php 如何在日历中显示我的Facebook好友的照片
我正在开发一个Facebook应用程序,我想在其中显示我朋友出生日期的照片。比如今天是四月二十六号,;如果我朋友的生日是今天,他/她的照片应该显示在26号的日历槽中,以此类推 以下是我目前的疑问:Php 如何在日历中显示我的Facebook好友的照片,php,facebook,facebook-graph-api,facebook-fql,Php,Facebook,Facebook Graph Api,Facebook Fql,我正在开发一个Facebook应用程序,我想在其中显示我朋友出生日期的照片。比如今天是四月二十六号,;如果我朋友的生日是今天,他/她的照片应该显示在26号的日历槽中,以此类推 以下是我目前的疑问: $dt = "April 12"; $fql1 = "SELECT uid,pic_big,pic,pic_small,name FROM user WHERE birthday='".$dt."' AND uid IN (SELECT uid2 FROM fr
$dt = "April 12";
$fql1 = "SELECT uid,pic_big,pic,pic_small,name
FROM user
WHERE birthday='".$dt."' AND
uid IN (SELECT uid2 FROM friend WHERE uid1= $user)";
我希望能够处理完整日期(即1986年4月12日)和部分日期(4月12日)
这是我的日历代码
<table width="100%" cellpadding="0" cellspacing="0" height="400" align="center" style="border:1px solid #cccccc;">
<tr><td colspan="3" align="center" class="viewlink"><?php echo $msg;?></td></tr>
<tr >
<td width="120" colspan="1" >
<input type="button" value=" < " onClick="goLastMonth(<?php echo $month . ", " . $year; ?>);">
</td>
<td colspan="5" width="610" align="center">
<span class="title"><?php echo $monthName . " " . $year; ?></span><br>
</td>
<td width="120" colspan="1" align="right" style="padding-right:2px;">
<input type="button" value=" > " onClick="goNextMonth(<?php echo $month . ", " . $year; ?>);">
</td>
</tr>
<tr>
<th>Sunday</td>
<th width="45">Mondy</th>
<th width="89">Tuesday</th>
<th width="126">Wednesday</th>
<th width="98">Thursday</th>
<th width="69">Friday</th>
<th>Saturday</th>
</tr>
<tr>
<?php
for($i = 1; $i < $numDays+1; $i++, $counter++){
$dateToCompare = $month . '-' . $i . '-' . $year;
$timeStamp = strtotime("$year-$month-$i");
//echo $timeStamp . '<br/>';
if($i == 1){
// Workout when the first day of the month is
$firstDay = date("w", $timeStamp);
for($j = 0; $j < $firstDay; $j++, $counter++){
echo "<td> </td>";
}
}
if($counter % 7 == 0){
?>
</tr><tr>
<?php
}
$pdate=strlen($i);
if($pdate==1)
{
$day="0".$i;
}
else
{
$day=$i;
}
$pmonth=strlen($month);
if($pmonth==1)
{
$mon="0".$month;
}
else
{
$mon=$month;
}
?>
<!--right here--><td width="323" <?=hiLightEvt($month,$i,$year);?> valign="top" style="font-family:Verdana, Geneva, sans-serif; font-size:12px; color:#960; text-align:center; padding:10px; margin:0; border:1px dotted #cccccc;" class="viewlink" ><?=$i;?><br />
<?php
**/////////////////////////////Here I want to display friends picture whose birthday at relevant date//////////////////////**
}
你的问题有点难理解;但据我所知,你很难找到你朋友的生日
我建议用另一种方式来解决这个问题。看起来您正在为日历中的每个日期执行一个FQL查询。我认为最好是加载所有用户的朋友,循环浏览每个朋友并推断日期。根据,生日日期格式与用户的区域设置有关,因此您无法可靠地查询该字段
另一种选择:(编辑的更加完整。现在几乎完全可以复制和粘贴。)
谢谢Jim的回复。我嵌入了这段代码,只显示数组()。其他什么都没有。你能告诉我怎样才能把它嵌入我的日历里吗。谢谢,很抱歉,我的代码中有一个错误-让我很快为您修复它。它在第36行,而不是$friend['birth'],您需要立即使用$birth\u ts.编辑。至于如何将其嵌入日历,我不知道您的日历生成脚本的详细信息,因此我不能很好地做到这一点。但是,$cur\u month\u birthdays数组是在每月的日期(M-DD)上编制索引的,因此您只需检查每个在该日期有生日的人的日期键。一个不存在的密钥意味着那天没有生日,但是如果有生日,那么每个在那一天有生日的用户都将是数组中的一个元素。Jim,你正在为我努力,但是亲爱的,结果是一样的。我的意思是它只是回声阵列()而已。事实上,下面是我的日历代码,我写日期评论区,朋友的照片将显示那个日期的生日。我把代码放在我以前的帖子里。我的意思是,现在我的问题更新了>@Mohammad Shafiq,我编辑了我的答案以显示示例输出,并添加了更多代码,使其几乎100%复制和粘贴,从而能够获得我的精确输出。你所要做的就是把你的应用程序信息放进去。你能试着格式化你的代码吗,所以的编辑器最近似乎有点疯狂,但我真的看不出你的代码在做什么,因为它没有格式化,而且缺少字符
<?php
$facebook = new Facebook(array(
'appId' => FB_APP_ID, //put your FB APP ID here
'secret' => FB_APP_SECRET, //put your FB APP SECRET KEY here
'cookie' => true
));
$session = $facebook->getSession();
if ($session)
{
//check to see if we have friends_birthday permission
$perms = $facebook->api('/me/permissions');
}
//we do this to see if the user is logged & installed
if (empty($session) || empty($perms['friends_birthday']))
{
//get url to oauth endpoint for install/login
$loginUrl = $facebook->getLoginUrl(array(
//put the URL to this page, relative to the FB canvas
//(apps.facebook.com) here vvv
'next' => 'http://apps.facebook.com/path_to_your_app/index.php',
'req_perms' => 'friends_birthday'
));
//use javascript to redirect. the oauth endpoint cant be loaded in an
//iframe, so we have to bust out of the iframe and load it in the browser
//and tell the oauth endpoint to come back to the fb canvas location
echo "<script>window.top.location='{$loginUrl}';</script>";
exit;
}
$user = $session['uid']; //load the user id from the session array
$cur_month_birthdays = array();
$cur_month = 4; //april
try {
$fql1 = "SELECT uid, pic_big, pic,pic_small, name, birthday FROM user "
. "WHERE uid IN ( "
. "SELECT uid2 FROM friend WHERE uid1 = {$user} "
. ")";
$friends = $facebook->api(array(
'method' => 'fql.query',
'query' => $fql1
));
//make sure i have some friends...
if (!empty($friends))
{
foreach ($friends as $friend)
{
//if this friend doesn't have their bday specified, skip them.
if (empty($friend['birthday']))
{
continue;
}
//get unix time for the users' birthday
$birthday_ts = strtotime($friend['birthday']);
//if this friends birthday is this month...
if (date('m', $birthday_ts) == $cur_month)
{
//generate a month-day string for the birthdate
$birthday_str = date('m-d', $birthday_ts);
//initialize the array of friends with birthdays on this date
if (empty($cur_month_birthdays[ $birthday_str ]))
{
$cur_month_birthdays[ $birthday_str ] = array();
}
$cur_month_birthdays[ $birthday_str ] []= $friend;
}
}
}
}
catch (Exception $e)
{
//error with facebook
error_log($e);
}
//output list of days in this month with friends that have birthdays
print_r($cur_month_birthdays);
Array
(
[04-04] => Array
(
[0] => Array
(
[uid] => 123123
[pic_big] => url-to-pic
[pic] => url-to-pic
[pic_small] => url-to-pic
[name] => Thomas W
[birthday] => April 4, 1985
)
)
[04-19] => Array
(
[0] => Array
(
[uid] => 123123
[pic_big] => url-to-pic
[pic] => url-to-pic
[pic_small] => url-to-pic
[name] => Joel S
[birthday] => April 19
)
)
[04-29] => Array
(
[0] => Array
(
[uid] => 123123
[pic_big] => url-to-pic
[pic] => url-to-pic
[pic_small] => url-to-pic
[name] => Ashley F
[birthday] => April 29, 1983
)
[1] => Array
(
[uid] => 123123
[pic_big] => url-to-pic
[pic] => url-to-pic
[pic_small] => url-to-pic
[name] => Megan S
[birthday] => April 29, 1989
)
)
)