【发布时间】:2012-01-31 11:19:56
【问题描述】:
我有一个客户项目,它将使用 YouTube 评论流作为一种“聊天”。我正在使用带有 Zend 框架的 GData API 对 YouTube 进行经过身份验证的调用。我正在寻找一种运行脚本的方法,该脚本将使用刷新按钮提取评论流,以便用户不必刷新页面即可查看他们的评论或出现的任何新 cmets。我相信这可以用 JQuery 来完成,但是经过一番搜索后,我还没有真正找到一个很好的解释。以下是我的代码的一些简短片段,让您对我正在查看的内容有所了解:
$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 语句以便于阅读。
【问题讨论】:
-
请更加努力地解释您要解决的确切问题。例如。修正标题并解释问题与代码示例之间的关系。这将使问题及其答案对未来的读者更有用。
标签: php jquery ajax zend-framework youtube-api