【问题标题】:Youtube API Limit CommentsYoutube API 限制评论
【发布时间】:2012-11-05 22:42:48
【问题描述】:

我正在使用以下代码将最近的 youtube cmets 检索到视频:

<?php
$videoId='lWA2pjMjpBs';
$url="http://gdata.youtube.com/feeds/api/videos/{$videoId}/comments";
$comments=simplexml_load_file($url);
foreach($comments->entry as $comment)
{
 echo '<fieldset>'.$comment->content.'</fieldset>';
}
?>

我有两个问题: 1) 有没有办法限制 cmets 的数量,所以我只能显示示例 10 cmets? 2) 是否可以排除被标记为垃圾邮件的 cmets?

谢谢。

【问题讨论】:

    标签: php api youtube youtube-api


    【解决方案1】:

    我不知道垃圾邮件,但你可以限制 nr。具有如下客户端解决方案的 cmets:

    $maxcomments = 10; //set max here
    $commentcounter = 0; //add this
    
    foreach($comments->entry as $comment)
    {
       if($commentcounter < $maxcomments)
       {
           echo '<fieldset>'.$comment->content.'</fieldset>';
       }
    
       $commentcounter++;
    }
    

    尚未对此进行检查,但它应该可以工作。我希望这会有所帮助。

    【讨论】:

    • 不客气,如果够用,请将其设置为已接受的答案。
    猜你喜欢
    • 1970-01-01
    • 2015-11-09
    • 2019-08-11
    • 1970-01-01
    • 2010-12-03
    • 2012-11-07
    • 1970-01-01
    • 2015-08-23
    • 2013-11-21
    相关资源
    最近更新 更多