如何在日历中显示我的 Facebook 好友的照片
我正在开发一个 Facebook 应用程序,我想在其中显示我朋友的照片和他的出生日期。例如,今天是 4 月 26 日;如果我朋友的生日是今天,他/她的照片应该显示在 26 日的日历槽中,依此类推。
到目前为止,这是我的查询:
$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//////////////////////**
}
?>
I'm developing a Facebook app in which I want to display the picture of my friend against his birth date. For example, today is April 26; if any of my friend's birthdays are today, his/her picture should display in the calendar slot for the 26th, etc.
Here's my query so far:
$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)";
I want to be able to handle both full dates (i.e. April 12, 1986) and partial dates (April 12).
This is my Calender code
<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//////////////////////**
}
?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你的问题有点难以理解;但据我所知 - 您在查找朋友特定日期的生日时遇到问题。
我建议以不同的方式解决这个问题。您似乎正在为日历中的每个日期执行单个 FQL 查询。我认为最好加载用户的所有朋友,然后循环遍历每个朋友并推断日期。根据 Facebook 文档,生日日期格式与用户的区域设置相关,因此您将无法可靠地查询该字段。
另一种选择:(编辑使其更加完整。现在几乎完全可以复制和粘贴。)
上面的代码将获取所有用户的朋友,循环遍历每个朋友,并找到生日位于当前月份(定义为
$cur_month
)。然后,您可以循环并构建日历,并每天检查 $cur_month_birthdays 数组以查看是否有任何朋友在当天过生日,并适当地显示它们。希望有帮助!
** 编辑 **
这是我对上述脚本的输出。我对其进行了编辑,使其设置更加彻底(包括 FB PHP SDK 的初始化和获取用户会话。我假设您至少有该代码。现在您可以看到数组的结构 - 您应该能够轻松地弄清楚如何集成到您的日历中。
Your question is a little hard to understand; but from what I do understand - you're having a problem finding your friends' birthdays for a specific date.
I would suggest going about this problem in a different way. It looks like you're doing a single FQL query for each date in your calendar. I think it'd be better to load all of a users' friends, and loop through each of them and extrapolate the date. According to Facebook's documentation, the birthday date format is relative to the users' locale, so you are not going to be able to reliably query against that field.
An alternative: (edited to be more complete. almost completely copy and pasteable now.)
The above code will fetch all your users' friends, loop through each, and find the ones with a birthday that is in your current month (defined as
$cur_month
). You can then loop through and build your calendar, and for each day you check the$cur_month_birthdays
array to see if there are any friends that have a birthday on the current day, and display them appropriately.Hope that helps!
** edit **
This is my output for the above script. I have edited it to be more thorough it's set-up (including initialization of the FB PHP SDK and fetching of the users' session. I had assumed that you had at least that code in place. Now that you can see the structure of the array - you should be able to easily figure out how to integrate into your calendar.