Question

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.

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top