>
Direct video upload to youtube code using zend fr...
Welcome, Guest

by Hemant on Wednesday, 04 February 2009
Direct video upload to youtube code using zend framework


Requirements

To use the PHP client library, you must be running PHP >= 5.1.4. You also need to be using Zend_Gdata >= 1.7.0, which is distributed as part of the Zend Framework.

There is also a sample application distributed with the client library which covers many of the API operations. The code is located in the /demos/YouTubeVideoApp folder.

Before you can perform any operations with the YouTube Data API, you must initialize a Zend_Gdata_YouTube object, as shown below. Please note that all actions aside from retrieving public content will require authentication.

<?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();
For authenticated functionality you will also need to include the one
of the following helper classes, pending on whether you plan to use
ClientLogin or AuthSub

Zend_Loader::loadClass('Zend_Gdata_AuthSub');

Zend_Loader::loadClass('Zend_Gdata_ClientLogin'); 

Authentication

The PHP client library can be used to work with either public or private feeds. Public feeds are read-only and do not require any authentication. Private feeds require that you authenticate to the YouTube servers. Additionally, you will need to sign up for a YouTube Developer Key. Authentication can be performed via ClientLogin, which uses username/password authentication or via AuthSub proxy authentication.

ClientLogin authentication

$authenticationURL= 'https://www.google.com/youtube/accounts/ClientLogin';
$httpClient
= Zend_Gdata_ClientLogin::getHttpClient(
                                          $username
= 'myuser@gmail.com',
                                          $password
= 'mypassword',
                                          $service
= 'youtube',
                                          $client
= null,
                                          $source
= 'MySource', // a short string identifying your application
                                          $loginToken
= null,
                                          $loginCaptcha
= null,
                                          $authenticationURL
);
$developerKey = 'ABC123 ... ';
$applicationId
= 'Video uploader v1';
$clientId
= 'My video upload client - v1';

$yt
= new Zend_Gdata_YouTube($httpClient, $applicationId, $clientId, $developerKey);

Uploading videos-Direct upload

The code below creates a blank VideoEntry to be uploaded. A Zend_Gdata_App_MediaFileSource object is then used to hold the actual video file. Unde the hood, the Zend_Gdata_YouTube_Extension_MediaGroup object is used to hold all of the video's meta-data. Our helper methods detailed below allow you to just set the video meta-data without having to worry about the media group object. The $uploadUrl is the location where the new entry gets posted to. This can be specified either with the $userName of the currently authenticated user, or, alternatively, you can simply use the string 'default' to refer to the currently authenticated user.

$yt = new Zend_Gdata_YouTube($httpClient);
// create a new Zend_Gdata_YouTube_VideoEntry object
$myVideoEntry
= new Zend_Gdata_YouTube_VideoEntry();

// create a new Zend_Gdata_App_MediaFileSource object
$filesource
= $yt->newMediaFileSource('mytestmovie.mov');
$filesource
->setContentType('video/quicktime');
// set slug header
$filesource
->setSlug('mytestmovie.mov');

// add the filesource to the video entry
$myVideoEntry
->setMediaSource($filesource);

$myVideoEntry
->setVideoTitle('My Test Movie');
$myVideoEntry
->setVideoDescription('My Test Movie');
$myVideoEntry
->setVideoCategory('Comedy'); // Note that category must be a valid YouTube category !

// set keywords, please note that this must be a comma separated string
// and that each keyword cannot contain whitespace
$myVideoEntry
->setVideoTags('cars, funny');

// optionally set some developer tags (see Searching by Developer Tags for more details)
$myVideoEntry
->setVideoDeveloperTags(array('mydevelopertag', 'anotherdevelopertag'));

// optionally set the video's location
$yt
->registerPackage('Zend_Gdata_Geo');
$yt
->registerPackage('Zend_Gdata_Geo_Extension');
$where
= $yt->newGeoRssWhere();
$position
= $yt->newGmlPos('37.0 -122.0');
$where
->point = $yt->newGmlPoint($position);
$myVideoEntry
->setWhere($where);

// upload URI for the currently authenticated user
$uploadUrl
= 'http://uploads.gdata.youtube.com/feeds/users/default/uploads';

// try to upload the video, catching a Zend_Gdata_App_HttpException if available
// or just a regular Zend_Gdata_App_Exception
try {
$newEntry
= $yt->insertEntry($myVideoEntry, $uploadUrl, 'Zend_Gdata_YouTube_VideoEntry');
} catch (Zend_Gdata_App_HttpException $httpException) {
echo $httpException
->getRawResponseBody();
} catch (Zend_Gdata_App_Exception $e) {
echo $e
->getMessage();
}
the code above will upload video to youtube you can upload max 10 min video to youtube.
as video is uploaded response is send back you can retrieve video id , video title ,video watch url etc from the response by code give below
  print '<br>videoid:---'.$newEntry->getVideoId();
print '<br>title-------'.$newEntry->getVideoTitle();
print '<br>url----'.$newEntry->getFlashPlayerUrl();
print '<br>watchurl-----'.$newEntry->getVideoWatchPageUrl();
put this file in library folder of zend framwork.
change response timeout time in file ZendGdata-1.7.3/library/Zend/Http/client.php    



Blogger Image
My Blog Title

Product Engineering, software engineering company, Product Development, Product Migration, Product Re-engineering, Product Maintenance, Product Testing Commercial Application Development, Business Software development, commercial software for startups, Application Support and Maintenance, software testing Product Maintenance, Outsource product maintenance, product support and maintenance Product Migration, Product Re-engineering, product re-engineering services Product Research, Product Engineering, UI Prototyping Services Software Testing Services, Quality Assurance services, professional software testers, Load Testing, Functional Testing, Cross Platform, Browser Testing, Test Automation, Testing Tools, software quality analysis Functional Testing Services, software quality analysis, Software Testing Services, Application Testing Services, Functional Testing Types Automated Testing, Automated Testing Services, automation testing, test script development, Automation Test Tools, outsource automation testing Load Testing, Performance Testing Services, Load Testing Tools Offshore Software Development, Outsource software services, offshore outsourcing services, offshore software development services, IT outsourcing services, software quality assurance services, Offshore IT services, Custom Application Development Services, Offshore Product Engineering Benefits of IT Outsourcing, Offshore Software Development companies, offshore software development firms Outsource planning, IT outsourcing, IT development services, offshore IT companies, offshore software development Offshore Software Development, Outsource software services, offshore outsourcing services, offshore software development services, IT outsourcing services, software quality assurance services, Offshore IT services, Custom Application Development Services, Offshore Product Engineering Offshore Software Development, Outsource software services, offshore outsourcing services, offshore software development services, IT outsourcing services, software quality assurance services, Offshore IT services, Custom Application Development Services, Offshore Product Engineering