0

我正在使用以下 PHP 代码来获取特定视频的评论:

<?php
    $vid = "G0k3kHtyoqc";
    $feedURL = 'http://gdata.youtube.com/feeds/api/videos/' . $vid;
    $entry = simplexml_load_file($feedURL);

    $gd = $entry->children('http://schemas.google.com/g/2005');
    if($gd->comments->feedLink){ 
        $attrs = $gd->comments->feedLink->attributes();
        $commentsURL = $attrs['href']; 
        $commentsCount = $attrs['countHint']; 
    }

    if($commentsURL && $commentsCount > 0){
      $commentsFeed = simplexml_load_file($commentsURL);    
      echo "<ol>";
      foreach($commentsFeed->entry as $comment){
        echo "<li>";
        echo "<a target='_blank' href='http://www.youtube.com/user/" . $comment->author->name . "'>";
        echo $comment->author->name;
        echo "</a>";
        echo " - " . $comment->content;
        echo "</li>";
      }
      echo "</ol>";
    }
?>

上面代码的问题是它只能获得最近的 24 条评论。我需要一种对所有评论进行分页的方法。

非常感谢您的帮助。

谢谢

4

1 回答 1

1

使用“开始索引”参数。从 1 开始,根据评论数,将 [comments-count] 添加到 start-index 参数。

例如:第一页评论,每页获得 25 条评论,使用 max-results=25 和 start-index=1 第二页评论,每页获得 25 条评论,使用 max-results=25 和 start-index=26

等等 =)

问候!

于 2013-04-02T00:32:02.000 回答