如何使用Zend Gdata YouTube获取视频评论用户个人资料?

时间:2015-03-09 06:18:59

标签: php zend-framework youtube

我想在youtube上获取视频的详细信息。除了在视频中发表评论的用户的照片之外,我能够获得详细信息。如何在没有在youtube上进行身份验证的情况下获得对视频进行评论的用户的照片  这是我的代码

$yt = new Zend_Gdata_YouTube();
$videoEntry = $yt->getVideoEntry($video_id);
$videoThumbnails = $videoEntry->getVideoThumbnails();

$videoDet = array(
        'thumbnail' => $videoThumbnails[0]['url'],
        'title' => $videoEntry->getVideoTitle(),
        'description' => $videoEntry->getVideoDescription(),
        'tags' => implode(', ', $videoEntry->getVideoTags()),
        'url' => $videoEntry->getVideoWatchPageUrl(),
        'flash' => $videoEntry->getFlashPlayerUrl(),
        'dura' => $videoEntry->getVideoDuration(),
        'id' => $videoEntry->getVideoId(),
        'Author' => $videoEntry->getAuthor(),
        'Content' => $videoEntry->getContent(),
        'Published' => $videoEntry->getPublished(),
        'Rating' => $videoEntry->getRating(),
        'Summary' => $videoEntry->getSummary(),
        'Duration' => $videoEntry->getVideoDuration(),
        'Comments' => $videoEntry->getComments(),
        'Viewer' => $videoEntry->getVideoViewCount(),
);

1 个答案:

答案 0 :(得分:0)

以这种方式找到,

        $yt = new Zend_Gdata_YouTube();
        $commentFeed = $yt->getVideoCommentFeed($video_id);

        foreach ($commentFeed as $commentEntry)
        {
            $feedURL = $commentEntry->author[0]->uri->text;

            $xmlReader = new XMLReader();
            $xmlReader->open(feedURL);
            while($xmlReader->read()) 
            {
                // check to ensure nodeType is an Element not attribute or #Text
                $thumbnail=$xmlReader->getAttributeNs('thumbnail','media');

                if($xmlReader->nodeType == XMLReader::ELEMENT) 
                {
                    if($xmlReader->localName == 'thumbnail') 
                    {
                        $photoUrl = $xmlReader->getAttribute('url');
                    }
                }
            }
        }