jump to navigation

Simple Use of YouTube’s API with Zend-Framework’s VideoEntry Component August 29, 2011

Posted by Tournas Dimitrios in PHP.

Zend Framework is a fully object-oriented framework , and as such ,  it utilizes a lot of object-oriented (OO) concepts like inheritance and interfaces . By design , Zend Framework is simply a collection of objects (classes) .The Framework contains ca 3000 files with over 800 components , from Authentication to AMF request/response functionality . These build in components can help you  develop any kind of functionality into your PHP project , experienced developers can even extend these components to create custom functionality . Normally , you’ll use Zend to create a fully functional MVC ZF- project that implements Enterprise level functionality , but  you can just load the components you need in simple PHP projects . ZF is very decoupled , which means we can take advantage of the components as individual libraries , instead of the framework as a whole . This article will demonstrate a simple example of using a single component (VideoEntry.php) from the Framework to query Youtube’s API .

Just follow these simple rules :

  •  Zend Framework requires PHP 5.2.4 or later since version 1.7.0 . Run a phpinfo() query on your host ,  be sure that your host supports the required PHP-version .
  • Create a “lib” folder in the root directory of your host . The “root directory ” contains the “public_html” directory where all your publicly accessible web-pages are stored . The “root directory” isn’t accessible by public requests .
      Upload the Framework into the “lib” location of your host .
  • Create a .htaccess file into the directory where the script will run with the following directive :
    php_value include_path “.:/Your-home-dir/Your-root-level-dir/lib”

    For example  , my configuration is similar to this :
    php_value include_path “.:/home/d9630823/lib”

  • That’s it , you are ready to start coding …

Let’s say you need a way to retrieve information about a specific video on YouTube. Zend_Gdata_Youtube is a ZF component which allows you to access data from YouTube via the GData API. Retrieving the video information is as simple as :

include_once "Zend/Gdata/Youtube.php";

$yt = new Zend_Gdata_YouTube();
// getVideoEntry takes in the YouTube video ID, which is usually the letters at the end
// of a YouTube URL e.g. http://www.youtube.com/watch?v=gTyOpHrZwoo

// the videoEntry object contains many helper functions
// that access the underlying mediaGroup object
$videoEntry = $yt->getVideoEntry('gTyOpHrZwoo');
echo 'Video: ' . $videoEntry->getVideoTitle()."";
echo 'Video ID: ' . $videoEntry->getVideoId()."";
echo 'Updated: ' . $videoEntry->getUpdated()."";
echo 'Description: ' . $videoEntry->getVideoDescription()."";
echo 'Category: ' . $videoEntry->getVideoCategory()."";
echo 'Tags: ' . implode(", ", $videoEntry->getVideoTags())."";
echo 'Watch page: ' . $videoEntry->getVideoWatchPageUrl()."";
echo 'Flash Player Url: ' . $videoEntry->getFlashPlayerUrl()."";
echo 'Duration: ' . $videoEntry->getVideoDuration()."";
echo 'View count: ' . $videoEntry->getVideoViewCount()."";
echo 'Rating: ' . $videoEntry->getVideoRatingInfo()."";
echo 'Geo Location: ' . $videoEntry->getVideoGeoLocation() ."";
echo 'Recorded on: ' . $videoEntry->getVideoRecorded()."";

foreach ($videoEntry->mediaGroup->content as $content) {
if ($content->type === "video/3gpp") {
echo 'Mobile RTSP link: ' . $content->url ."";
echo "Thumbnails:";
$videoThumbnails = $videoEntry->getVideoThumbnails();
foreach($videoThumbnails as $videoThumbnail) {
echo $videoThumbnail['time'] . ' - ' . $videoThumbnail['url'];
echo ' height=' . $videoThumbnail['height'];
echo ' width=' . $videoThumbnail['width'] . "";

A demonstration of this script on my server .

Read more :


1. Integrating PHP Applications with Google’s Data Protocol « Tournas Dimitrios - February 27, 2012

[…] the Google API’s that use the Google Data Protocol ). An older article of this Blog  ”Simple Use of YouTube’s API with Zend-Framework’s VideoEntry Component ” demonstrated the use of Zend’s  Zend_Gdata component , this article will present a […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s