开发者

YouTube API videoEntry count comments

开发者 https://www.devze.com 2022-12-10 04:49 出处:网络
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?

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?

<?ph开发者_如何学JAVAp
    $commentFeed = $yt->getVideoCommentFeed($videoID);
    if ( count($commentFeed) > 0 )
    {
        foreach ($commentFeed as $commentEntry)
        {
            // print commentEntry
        }
    }
 ?>


The comments count can be accessed by:

$yt->getVideoCommentFeed($videoID)->totalResults->text


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, 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)

0

精彩评论

暂无评论...
验证码 换一张
取 消