从YouTube频道的上传Feed中的条目中获取喜欢/不喜欢的计数

时间:2013-04-22 17:22:46

标签: youtube-api

我正在尝试检索频道Feed中的喜欢和不喜欢的数量。但只得到每个视频的评级。有没有办法从喜欢和不喜欢的地方获取这些信息?

我的代码:

// set feed URL
$feedURL = "http://gdata.youtube.com/feeds/api/users/GoogleDevelopers/uploads";

// read feed into SimpleXML object
$sxml = simplexml_load_file($feedURL);

// get <gd:rating> node for video ratings
$gd = $entry->children('http://schemas.google.com/g/2005');

foreach ($sxml->entry as $entry) {

      if ($gd->rating) {
        $attrs = $gd->rating->attributes();        
        $rating = $attrs['average'];                
      }

      /*
       * does not work
       *
        $yt = $entry->children('http://gdata.youtube.com/schemas/2007');
        $attrs = $yt->rating->attributes();
        $dislikes = $attrs['numDislikes'];
        $likes = $attrs['numLikes'];
      */

}

任何人都可以帮助我吗?

1 个答案:

答案 0 :(得分:0)

您需要包含v=2参数,以指定您想要支持喜欢/不喜欢的Data API的v2。

此外,如果添加alt=jsonc,您可能会发现更容易,因为您可以使用JSON而不是XML。例如。 http://gdata.youtube.com/feeds/api/users/GoogleDevelopers/uploads?v=2&alt=jsonc