I am using the following code to upload small and large videos on youtube. The code properly works on localhost but when I run it on server and upload the same videos, it uploads all the SMALL files but not the large files. Once upload is completed youtube shows following Error for files with large size: Failed (unable to convert video file)
<?php
require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata_YouTube');
Zend_Loader::loadClass('Zend_Gdata_AuthSub');
Zend_Loader::loadClass('Zend_Gdata_App_Exception');
session_start();
$_SESSION['Key'] = 'My Developer Key';
?>
<html>
<head>
</head>
<body>
<?php
if (!isset($_SESSION['sessionToken']) && !isset($_GET['token']) ){
echo '<a href="' . getAuthSubRequestUrl() . '">Login!</a>';
} else if (!isset($_SESSION['sessionToken']) && isset($_GET['token'])) {
$_SESSION['sessionToken'] = Zend_Gdata_AuthSub::getAuthSubSessionToken($_GET['token']);
}
if(isset($_SESSION['sessionToken']))
{
$yt = new Zend_Gdata_YouTube(getAuthSubHttpClient());
$myVideoEntry = new Zend_Gdata_YouTube_VideoEntry();
$filesource = $yt->newMediaFileSource('myvideo.mov');
$filesource->setContentType('video/quicktime');
$filesource->setSlug('myvideo.mov');
$myVideoEntry->setMediaSource($filesource);
$myVideoEntry->setVideoDescription('this is my test video');
$myVideoEntry->setVideoCategory("Music");
$myVideoEntry->setVideoTitle('this is videoo');
$myVideoEntry->SetVideoTags('tag1');
$uploadUrl ='http://uploads.gdata.youtube.com/feeds/users/default/uploads';
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();
}
}
?>
</body>
</html>
<?php
function getAuthSubRequestUrl()
{
$next = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
$scope = 'http://gdata.youtube.com';
$secure = false;
$session = true;
return Zend_Gdata_AuthSub::getAuthSubTokenUri($next, $scope, $secure, $session);
}
function getAuthSubHttpClient()
{
if (!isset($_SESSION['sessionToken']) && !isset($_GET['token']) ){
echo '<a href="' . getAuthSubRequestUrl() . '">Login!</a>';
return;
} else if (!isset($_SESSION['sessionToken']) && isset($_GET['token'])) {
$_SESSION['sessionToken'] = Zend_Gdata_AuthSub::getAuthSubSessionToken($_GET['token']);
}
$httpClient = Zend_Gdata_AuthSub::getHttpClient($_SESSION['sessionToken']);
$httpClient->setHeaders('X-GData-Key', 'key='. $_SESSION['Key']);
return $httpClient;
}
function updateAuthSubToken($singleUseToken)
{
try {
$sessionToken = Zend_Gdata_AuthSub::getAuthSubSessionToken($singleUseToken);
} catch (Zend_Gdata_App_Exception $e) {
print 'ERROR - Token upgrade for ' . $singleUseToken
. ' failed : ' . $e->getMessage();
return;
}
$_SESSION['sessionToken'] = $sessionToken;
generateUrlInformation();
header('Location: ' . $_SESSION['homeUrl']);
}
?>
Here is a complete PHP example to upload large files.