Albi Hoti
Albi Hoti

Reputation: 351

Youtube API Limit Comments

Im using below code to retrieve recent youtube comments to a video:

<?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>';
}
?>

and i have 2 questions: 1) is there any way to limit number of comments, so I can display only example 10 comments? 2) is possible to exclude comments that are marked as spam?

Thanks.

Upvotes: 0

Views: 416

Answers (1)

Erik Klop
Erik Klop

Reputation: 135

I don't know about the spam but you could limit the nr. of comments with a client-side solution like this:

$maxcomments = 10; //set max here
$commentcounter = 0; //add this

foreach($comments->entry as $comment)
{
   if($commentcounter < $maxcomments)
   {
       echo '<fieldset>'.$comment->content.'</fieldset>';
   }

   $commentcounter++;
}

haven't checked this, but it should work. I hope this helped.

Upvotes: 1

Related Questions