Zend Framework 101: Zend_Gdata_YouTube
Retrieving a List of Videos
To get started with Zend_Gdata_YouTube all you need to do is include the Zend/Gdata/YouTube.php file, then instantiate the class. No arguments are required when instantiating Zend_Gdata_YouTube.
Zend_Gdata_YouTube.
The Zend_Gdata_YouTube class contains a helper method called getUserUploads() which is used to retrieve all videos for the user specified in the first argument. If the username is not valid, an exception is thrown.
Listing 1 shows how to load and instantiate the class, then retrieve all videos for the username ReciteCMS. To compare the results of your code with the real data, view the ReciteCMS channel on YouTube.
require_once('Zend/Gdata/YouTube.php'); $username = 'ReciteCMS'; $youtube = new Zend_Gdata_YouTube(); try { $feed = $youtube->getUserUploads($username); } catch (Exception $ex) { echo $ex->getMessage(); exit; } // output the feed data here
A successful call to getUserUploads() returns an instance of
Zend_Gdata_YouTube_VideoFeed. This class implements the Iterator interface, meaning you can loop directly over the object to access each video.
require_once('Zend/Gdata/YouTube.php'); $username = 'ReciteCMS'; $youtube = new Zend_Gdata_YouTube(); try { $feed = $youtube->getUserUploads($username); } catch (Exception $ex) { echo $ex->getMessage(); exit; } foreach ($feed as $video) { // output the details of a single video }
In the next section I'll show you how to output the details of each video.




