如何提取有关单个视频的信息 - Youtube API


how to extract information about a single video - Youtube API

文档中

有一个如何按搜索词搜索视频的示例,但是当您拥有videoID时,如何从单个视频中提取信息。

<?php
  // set feed URL
    $feedURL = 'http://gdata.youtube.com/feeds/api/videos/LjhCEhWiKXk?v=2';
    // read feed into SimpleXML object
    $sxml = simplexml_load_file($feedURL);

// this get the video title
$videoTitle = $sxml->title;

?>

我只得到视频标题...也没有观看次数,描述和持续时间。

这对我很有用: 访问 将 YouTube API 与 PHP 一起使用

您必须完全解析视频条目 ($sxml) 才能获取更多信息:

入口$sxml的子节点:

// get nodes in media: namespace for media information
$media = $entry->children('http://search.yahoo.com/mrss/');

获取持续时间:($media->儿童...

** 媒体:组元素下的元素 yt:持续时间 存储视频的长度,以秒为单位**

// get <yt:duration> node for video length
$yt = $media->children('http://gdata.youtube.com/schemas/2007');
$attrs = $yt->duration->attributes();
$obj->length = $attrs['seconds'];