【问题标题】:Get youtube video comment details using PHP使用 PHP 获取 youtube 视频评论详细信息
【发布时间】:2014-04-20 10:04:42
【问题描述】:

我正在尝试使用 PHP 获取给定视频的 youtube 视频 cmets。我正在使用 Zend 框架。以下是我的代码 sn-p

$yt = new Zend_Gdata_Youtube();
$feeds = $yt->getVideoCommentFeed($id);  // $id is youtube id
while ($feeds) {
     foreach ($feeds as $idx => $feed) {
          echo $feed->getTitle()."\n"; // work and display the beginning of comment
          $author = $feed->getAuthor(); 
          // how to get author name and/or id?
          $date = $feed->getPublished();
          // how to get the date out if it?

     }
     $feeds = $yt->getVideoFeed($feeds->getNextLink());
}

如何获取每条评论的作者姓名/ID、发表时间和其他信息?我无法从 Zend 文档中找到该信息。

提前致谢,

【问题讨论】:

    标签: php zend-framework youtube youtube-api gdata-api


    【解决方案1】:
    $yt = new Zend_Gdata_YouTube();
    $commentFeed = $yt->getVideoCommentFeed('abc123813abc');
    
    foreach ($commentFeed as $commentEntry) {
        echo $commentEntry->title->text . "\n";
        echo $commentEntry->content->text . "\n";
        echo $commentEntry->author[0]->name->text. "\n";
        echo $commentEntry->author[0]->uri->text. "\n"; 
        echo $commentEntry->published->text. "\n";
    }
    

    对于 Vlogbrothers 供稿:

    http://gdata.youtube.com/feeds/api/videos/og8cxXICoVU/comments
    

    示例评论条目

    <entry>
        <id>http://gdata.youtube.com/feeds/api/videos/og8cxXICoVU/comments/z13tuzmrbk2cszxbx04cjdcoyva4jjliu0c</id>
        <published>2014-03-09T20:16:01.000Z</published>
        <updated>2014-03-09T20:16:01.000Z</updated>
        <category scheme="http://schemas.google.com/g/2005#kind" term="http://gdata.youtube.com/schemas/2007#comment"/>
        <title type="text">i also highly ...</title>
        <content type="text">i also highly recommend Chop socky chooks- ninja chickens with a piece of 
    wasabi as their arch nemesis.</content>
        <link rel="related" type="application/atom+xml" href="http://gdata.youtube.com/feeds/api/videos/og8cxXICoVU"/>
        <link rel="alternate" type="text/html" href="http://www.youtube.com/watch?v=og8cxXICoVU"/>
        <link rel="self" type="application/atom+xml" href="http://gdata.youtube.com/feeds/api/videos/og8cxXICoVU/comments/z13tuzmrbk2cszxbx04cjdcoyva4jjliu0c"/>
        <author>
          <name>Jade Collins</name>
          <uri>http://gdata.youtube.com/feeds/api/users/NGsitBKTSKzO-Fioyjy4dw</uri>
        </author>
        <yt:channelId>UCNGsitBKTSKzO-Fioyjy4dw</yt:channelId>
        <yt:googlePlusUserId>118173943933565439685</yt:googlePlusUserId>
        <yt:replyCount>0</yt:replyCount>
        <yt:videoid>og8cxXICoVU</yt:videoid>
      </entry>
    

    【讨论】:

    • 谢谢,阿奇。现在看评论条目就很清楚了。我试图打印每条评论,它看起来很模糊。谢谢
    • 为了避免分页次数过多,我正在尝试增加每页的提要数量。我试过 $commentFeed.setItemsPerPage() 但它没有任何效果。只是想知道你是否知道如何实现这一目标?谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-10-10
    • 1970-01-01
    • 2012-06-09
    • 2019-03-08
    • 1970-01-01
    • 2015-08-23
    • 2016-05-23
    相关资源
    最近更新 更多