1

I'm unable to find any documentation where I can find a code example for receiving the likes and dislikes of a video. That's my current code:

$videoId = 'AyJl2NyQ0hI';
$videoEntry = $yt->getVideoEntry($videoId);

echo "Views: <strong>".$videoEntry->getVideoViewCount()."</strong><br />";

It works fine, but who to get the likes/dislikes? Thanks.

4

1 回答 1

9

Just look through the source for classes Zend_Gdata_YouTube_VideoEntry and Zend_Gdata_YouTube_Extension_Statistics:

$videoEntry->getStatistics()->getViewCount();

Edit: You edited your question and you are now looking for Likes/Dislikes

Step 1: Change the protocol version to v2

$yt = new Zend_Gdata_YouTube();
$yt->setMajorProtocolVersion(2);

Step 2: The last stable release of the zend gdata youtube client is missing methods to access the likes and dislikes, but the data is returned. You can get at it by looking through the extension attributes of the Rating extension:

$videoId = 'AyJl2NyQ0hI';
$videoEntry = $yt->getVideoEntry($videoId);

foreach ($videoEntry->getExtensionElements() as $extension)
{
    if ($extension->rootElement == 'rating')
    {
        $attributes = $extension->getExtensionAttributes();
        var_dump($attributes);
    }
}

Which should return:

array(2) {
  ["numDislikes"]=>
  array(3) {
    ["namespaceUri"]=>
    NULL
    ["name"]=>
    string(11) "numDislikes"
    ["value"]=>
    string(2) "57"
  }
  ["numLikes"]=>
  array(3) {
    ["namespaceUri"]=>
    NULL
    ["name"]=>
    string(8) "numLikes"
    ["value"]=>
    string(3) "657"
  }
}
于 2012-05-31T17:19:17.340 回答