views:

113

answers:

2

I am trying to get the comment count for a video entry but this is giving me a count of 1 when there are no comments. Any ideas?

<?php
    $commentFeed = $yt->getVideoCommentFeed($videoID);
    if ( count($commentFeed) > 0 )
    {
        foreach ($commentFeed as $commentEntry)
        {
            // print commentEntry
        }
    }
 ?>
A: 

I'm not familiar with the PHP version of the API (I've only used the Python one) but I am pretty sure your issue is that when you get $commentFeed, it is returning the full comment feed XML. This includes a root element named <feed> with a bunch of <entry> elements.

So, what you should probably be doing is checking to see if entry within $commentFeed is greater than zero or exists.

Bartek
A: 

Bartek, To my knowledge the commentFeed from Google only contains the most recent 25 <entry>.

As far as the original question, without knowledge of what the $commentFeed object contains, it's difficult to answer your question. My suggestion would be to print_r($commentFeed) and see what you are dealing with. I believe it will be something more like count($commentFeed->entry)

Jason McCreary