2

Youtube の動画情報を取得する方法をいろいろと検索しましたが、いくつかの良い結果が得られましたが、まだ 1 つの問題があります。一部の動画では、私のコードが評価を取得しません。

私のコード:

$feedURL = 'http://gdata.youtube.com/feeds/api/videos/' . $link;
$entry = simplexml_load_file($feedURL);
$video = parseVideoEntry($entry);

$rating = $video->rating;
$ratingf = (float)$rating*20;

function parseVideoEntry($entry) {      
$obj= new stdClass;

 $gd = $entry->children('http://schemas.google.com/g/2005'); 
 if ($gd->rating) { 
   $attrs = $gd->rating->attributes();
   $obj->rating = $attrs['average']; 
 } else {
   $obj->rating = 0;         
 }
 return $obj;
}

そのため、一部のビデオでこの 0 を取得していますが、その理由を見つけることができません。動画によって違いはありますか?

4

1 に答える 1

0

このツールをきっと気に入っていただけるはずです: google developers youtube api

これは、API を自分で照会して取得する JSON を提供します。例:

{
 "kind": "youtube#videoListResponse",
 "etag": "\"g-RLCMLrfPIk8n3AxYYPPliWWoo/lmFpi-LTJ4YMpq66PF5yr558nV8\"",
 "pageInfo": {
  "totalResults": 1,
  "resultsPerPage": 1
 },
 "items": [
  {

   "id": "9bZkp7q19f0",
   "kind": "youtube#video",
   "etag": "\"g-RLCMLrfPIk8n3AxYYPPliWWoo/g7hwtchXAeaF-Q1DpUEFJXvRfbY\"",
   "statistics": {
    "viewCount": "1621240530",
    "likeCount": "7577258",
    "dislikeCount": "787002",
    "favoriteCount": "0",
    "commentCount": "5969060"
   }
  }
 ]
}

中を見likedislike数えることができますstatistics。そのため、応答について確信が持てない場合はいつでも、ツールをチェックして、必要なものがすべて揃っているかどうかを確認してください。

于 2013-05-26T18:46:40.333 に答える