Progress Bar For Youtube Direct Uploads With Data?
I would like to display a progress bar for direct youtube uploads using the gdata api. I have the uploads getting kicked off in by an ajax call to an uploader.php script, and when
Solution 1:
You can create a php page and do a "browser based upload" using CURL. This means that you have control over the upload and you can create a progress bar. Here is an example of how an upload might look like. The bottom part of this code is the interesting part. It makes an "browser based upload" using CURL and then returns the result;
// upload.phprequire_once'Zend/Loader.php'; // the Zend dir must be in your include_path
Zend_Loader::loadClass('Zend_Gdata_YouTube');
$yt = new Zend_Gdata_YouTube();
// Define the authentication that will be used
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
// Authenticate$authenticationURL= 'https://www.google.com/accounts/ClientLogin';
$httpClient =
Zend_Gdata_ClientLogin::getHttpClient(
$username = "USERNAME",
$password = "PASSWORD",
$service = 'youtube',
$client = null,
$source = 'HTML SOURCE CODE SNIPPET',
$loginToken = null,
$loginCaptcha = null,
$authenticationURL);
$applicationId = 'YOUR APPLICATION ID';
$clientId = 'Upload videos to youtube using the youtube API';
$developerKey = 'YOUR DEVELOPER KEY';
$yt = new Zend_Gdata_YouTube($httpClient, $applicationId, $clientId, $developerKey);
// create a new VideoEntry object$myVideoEntry = new Zend_Gdata_YouTube_VideoEntry();
$myVideoEntry->setVideoTitle($videoTitle);
$myVideoEntry->setVideoDescription($VideoDescription);
// The category must be a valid YouTube category!$myVideoEntry->setVideoCategory($VideoCategory);
// Set keywords. Please note that this must be a comma-separated string// and that individual keywords cannot contain whitespace$myVideoEntry->SetVideoTags($VideoTags);
$tokenHandlerUrl = 'http://gdata.youtube.com/action/GetUploadToken';
$tokenArray = $yt->getFormUploadToken($myVideoEntry, $tokenHandlerUrl);
$tokenValue = $tokenArray['token'];
$postUrl = $tokenArray['url'];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $postUrl."?nexturl=http://YOUR_WEBPAGE.com/");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_POST, true);
// same as <input type="file" name="file">$post = array("file"=>"@".$VideoFile['tmp_name'], "token"=>$tokenValue);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
echo$info;
You can read more here https://developers.google.com/youtube/2.0/developers_guide_php#Browser_based_Upload
Post a Comment for "Progress Bar For Youtube Direct Uploads With Data?"