我有一个客户端项目将使用YouTube评论流作为一种“聊天”。我正在使用带有Zend Framework的GData API对YouTube进行认证。我正在寻找一种方法来运行脚本,该脚本将使用刷新按钮提取评论流,以便用户不必刷新页面以查看他们的评论或出现的任何新评论。我相信这可以用JQuery来完成,但是经过一番搜索后,我还没有真正找到一个很好的解释。下面是我的代码一些简短snippits给你什么,我看一些想法:使用jQuery获取Youtube评论
$yt = new Zend_Gdata_YouTube($httpClient, $applicationId, $clientId, $developerKey);
$_SESSION['yt'] = serialize($yt);
/***************** Adds a comment if applicable *****************/
if(isset($_POST['btn_submit']))
{
$videoEntry = $yt->getVideoEntry('QQoFLrZ5C3M');
$newComment = $yt->newCommentEntry();
$newComment->content = $yt->newContent()->setText($_POST['comment']);
// post the comment to the comments feed URL for the video
$commentFeedPostUrl = $videoEntry->getVideoCommentFeedUrl();
$updatedVideoEntry = $yt->insertEntry($newComment, $commentFeedPostUrl,
'Zend_Gdata_YouTube_CommentEntry');
}
/****************************************************************/
<div id="coments">
$commentFeed = $yt->getVideoCommentFeed('QQoFLrZ5C3M');
echo '<div id="refresh"><a href="#" style="margin-right: 15px; border: 0;"><img src="../common/img/refresh.png" alt="refresh" border="0" /></a></div>';
foreach ($commentFeed as $commentEntry) {
echo '<div class="comment">';
echo '<a href="http://youtube.com/user/' . utf8_decode(utf8_encode($commentEntry->author[0]->name->text)) . '" target="_blank" class="youtube_user">' . utf8_decode(utf8_encode($commentEntry->author[0]->name->text)) . '</a><br />';
echo '<span style="font-size: 14px;">' . utf8_decode(utf8_encode($commentEntry->content->text)) . '</span><br />';
// Format time
$timeAgoObject = new convertToAgo;
$ts = strtotime($commentEntry->updated->text);
$timestamp = ($timeAgoObject -> makeAgo($ts)); // Then convert to ago time
echo '<div class="yt_timestamp">' . $timestamp . '</div>';
echo '</div>';
}
?>
</div>
注意,YouTube的类并不总是新的(因此序列化到一个会话变量)我刚刚剥离出来if语句易于阅读。
请些精力在解释你正在试图解决的确切问题。例如。修正题目并解释问题与代码示例之间的关系。这将使问题及其答案对未来的读者更有用。 – 2012-01-01 20:15:34