dougu1990 2012-02-24 16:15
浏览 124
已采纳

如何使用youtube api和php在youtube中查看用户的收藏视频

I want to be able to read the favorite videos of a user from youtube using the youtube-api in php. So far I have this:

index.php `

<?php
    require_once 'Zend/Loader.php'; // the Zend dir must be in your include_path
    Zend_Loader::loadClass('Zend_Gdata_YouTube');
    $yt = new Zend_Gdata_YouTube();

    $yt->setMajorProtocolVersion(2);
    $favoritesFeed = $yt->getUserFavorites('cartmanland911');

   foreach($activityFeed as $activityEntry) {
       $title = $activityEntry->getVideoTitle();
       echo "favorited video " . $title . '<br/>';
   }
?>`

The zend framework is in the same folder as the index.php file and the framework loads ok.

Calling echo $favoritesFeed->getDOM()->hasChildNodes(); outputs 1

Also, calling echo $favoritesFeed->count(); outputs 6 which is correct(i have 6 favorite videos)

So, the question is how do I read the name of each of those favorite videos?

EDIT: Added another solution above.

  • 写回答

1条回答 默认 最新

  • dongmeng1868 2012-02-24 17:32
    关注

    You might want to consider the PHP XQuery extension in order to do this:

    import module namespace http = "http://expath.org/ns/http-client";
    
    declare namespace a = "http://www.w3.org/2005/Atom";
    
    let $req := <http:request method="GET" href="http://gdata.youtube.com/feeds/base/users/cartmanland911/favorites" />
    let $feed := http:send-request($req, ())[2]/a:feed
    for $entry in $feed/a:entry
    return <h1>{$entry/a:title/text()}</h1>
    

    You can try the following example live at http://www.zorba-xquery.com/html/demo#ZOFhRE4SYzli8jy+39WJyegnhy4= Instructions on how to install the XQuery PHP extension are available at http://www.zorba-xquery.com/html/entry/2011/12/27/PHP_Meets_XQuery

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题