dougu1990 2012-02-24 08: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 09: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

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

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部