Showing posts with label video. Show all posts
Showing posts with label video. Show all posts

Wednesday, May 16, 2012

Upload Video To Youtube Using Php Script

DOWNLOAD ZEND DATA FROM:
http://framework.zend.com/download/gdata
OR
https://www.box.com/s/e28da8suyty2nc3jtm72
OR
https://docs.google.com/file/d/0B5nZNPW48dpFMTJPMks3WWZtd0E/edit?usp=sharing

set that root folder in project

index.php:

<?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();

Zend_Loader::loadClass('Zend_Gdata_AuthSub');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');

session_start();
/* your next url */
$next = 'http://localhost/phpYouTube/welcome.php';
$scope = 'http://gdata.youtube.com';
$secure = false;
$session = true;
$returnData = Zend_Gdata_AuthSub::getAuthSubTokenUri($next, $scope, $secure, $session);
header("Location: ".$returnData);
?>


welcome.php

<?php
require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata_YouTube');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
$authenticationURL= 'https://www.google.com/accounts/ClientLogin';
$httpClient = Zend_Gdata_ClientLogin::getHttpClient(
        $username = 'name@gmail.com',
        $password = 'password',
        $service = 'youtube',
        $client = null,
        $source = 'MySource', // a short string identifying your application
        $loginToken = null,
        $loginCaptcha = null,
        $authenticationURL);

$developerKey = 'DEVELOPER KEY'; /* https://code.google.com/apis/youtube/dashboard */
$applicationId = 'Video uploader v1';
$clientId = 'My video upload client - v1';

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

$myVideoEntry = new Zend_Gdata_YouTube_VideoEntry();
$filesource = $yt->newMediaFileSource('C:\Users\Public\Videos\Sample Videos\\Wildlife.wmv');
$filesource->setContentType('video/quicktime');
$filesource->setSlug('Wildlife.wmv');
$myVideoEntry->setMediaSource($filesource);
$myVideoEntry->setVideoTitle('My Test Movie');
$myVideoEntry->setVideoDescription('My Test Movie');
// The category must be a valid YouTube category!
$myVideoEntry->setVideoCategory('Autos');
// Set keywords. Please note that this must be a comma-separated string
// and that individual keywords cannot contain whitespace
$myVideoEntry->SetVideoTags('personal');
// set some developer tags -- this is optional
// (see Searching by Developer Tags for more details)
$myVideoEntry->setVideoDeveloperTags(array('mydevtag', 'anotherdevtag'));

// upload URI for the currently authenticated user
$uploadUrl = 'http://uploads.gdata.youtube.com/feeds/api/users/default/uploads';
// try to upload the video, catching a Zend_Gdata_App_HttpException,
// if available, or just a regular Zend_Gdata_App_Exception otherwise
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();
}
}
?>