在php中打印YouTube视频Feed

时间:2013-05-01 12:27:05

标签: php wordpress youtube wordpress-plugin youtube-api

我正处于编写插件的开始阶段,以在WordPress实现中显示YouTube视频。这是我的代码:

require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata_Youtube');
$yt = new Zend_Gdata_YouTube();

function getAndPrintVideoFeed($location::'http://gdata.youtube.com/feeds/api/users/thelanzolini/uploads/-/step') {
  $yt = new Zend_Gdata_YouTube();
  // set the version to 2 to receive a version 2 feed of entries
  $yt->setMajorProtocolVersion(2);
  $videoFeed = $yt->getVideoFeed($location);
  printVideoFeed($videoFeed);
}

function printVideoFeed($videoFeed) {
  $count = 1;
  foreach ($videoFeed as $videoEntry) {
    echo "Entry # " . $count . "\n";
    printVideoEntry($videoEntry);
    echo "\n";
    $count++;
  }
}

我得到的只是这个错误:

enter image description here

我正在使用MAMP。 php是版本5.4.10。

切换$location::以上的$location =我在实际的插件文件本身中没有错误,而是加载了Zend的各种组件。

错误:

  

警告:include_once(Zend / Gdata / Youtube.php):无法打开流:   在......中没有该文件或目录   /Users/mrcsmcln/Documents/MAMP/wordpress/wp-content/plugins/youtube-filter/Zend/Loader.php   在第134行

     

警告:include_once():无法打开'Zend / Gdata / Youtube.php'   包容   (include_path ='。:/ Applications / MAMP / bin / php / php5.4.10 / lib / php')in   /Users/mrcsmcln/Documents/MAMP/wordpress/wp-content/plugins/youtube-filter/Zend/Loader.php   在第134行

     

警告:require_once(Zend / Exception.php):无法打开流:否   这样的文件或目录   /Users/mrcsmcln/Documents/MAMP/wordpress/wp-content/plugins/youtube-filter/Zend/Loader.php   第86行

     

致命错误:require_once():无法打开所需的错误   '的Zend / Exception.php'   (include_path ='。:/ Applications / MAMP / bin / php / php5.4.10 / lib / php')in   /Users/mrcsmcln/Documents/MAMP/wordpress/wp-content/plugins/youtube-filter/Zend/Loader.php   第86行

我的代码出了什么问题?有没有比这更好的方法呢?

1 个答案:

答案 0 :(得分:0)

function getAndPrintVideoFeed($location::'http://gdata.youtube.com/feeds/api/users/thelanzolini/uploads/-/step') {
  $yt = new Zend_Gdata_YouTube();
  // set the version to 2 to receive a version 2 feed of entries
  $yt->setMajorProtocolVersion(2);
  $videoFeed = $yt->getVideoFeed($location);
  printVideoFeed($videoFeed);
}

应该?可能?是这样的:不熟悉ZF但是这至少是常规语法。

function getAndPrintVideoFeed($location = 'http://gdata.youtube.com/feeds/api/users/thelanzolini/uploads/-/step') {
  $yt = new Zend_Gdata_YouTube();
  // set the version to 2 to receive a version 2 feed of entries
  $yt->setMajorProtocolVersion(2);
  $videoFeed = $yt->getVideoFeed($location);
  printVideoFeed($videoFeed);
}