我的要求很简单。我需要提取视频的YouTube评级,获取喜欢和不喜欢的内容。返回%喜欢。所以喜欢除以总数。每次有人点击“下一个视频”时,这都会更新。
这是我的代码:
<!-- HTML DOCTYPE -->
<?php
$url = 'http://gdata.youtube.com/feeds/api/videos/' . $vid . '?v=2';
// get <yt:rating> node for like/dislikes
$yt = $entry->children('http://gdata.youtube.com/schemas/2007');
$attrs = $yt->rating->attributes();
$obj->dislikes = $attrs['numDislikes'];
$obj->likes = $attrs['numLikes'];
$total = (likes + dislikes);
$rating = (likes/total);
echo $obj->rating;
}
?>
然后它在这里输出:
<div id="ratingNum" class="col-1-2 ps fl center">92%</div>