Sunteți pe pagina 1din 2

<?

php /** * @author ambika * @copyright 2011 * example to demonstrate differnt users uploading to the same youtube channel * user can select the video and upload to the predefined(single) youtube channe l/location * combination of the direct uploading and browser based uploading */ require_once 'Zend/Loader.php'; Zend_Loader::loadClass('Zend_Gdata_YouTube'); Zend_Loader::loadClass('Zend_Gdata_ClientLogin'); Zend_Loader::loadClass('Zend_Gdata_AuthSub'); Zend_Loader::loadClass('Zend_Gdata_App_Exception'); $serviceName = Zend_Gdata_YouTube::AUTH_SERVICE_NAME; // predefined service name ('cl') for calendar $applicationName = '<your app name>';// application name $developer_key = '<developer key>';// developer key // Create an authenticated HTTP client $httpClient = Zend_Gdata_ClientLogin::getHttpClient('<channel login email>', '<p ass>', $serviceName, null, $applicationName);// provide the constant channel log in email and password to ensure thet every users upload to the same channel $httpClient->setHeaders('X-GData-Key', 'key='. $developer_key); $yt = new Zend_Gdata_YouTube($httpClient); // create a new VideoEntry object $myVideoEntry = new Zend_Gdata_YouTube_VideoEntry(); $myVideoEntry->setVideoTitle('My Test Movie');// Edit this to provide the custom title or can be taken from form $myVideoEntry->setVideoDescription('My Test Movie');// Edit this to provide the custom description or can be taken from form // The category must be a valid YouTube category! $myVideoEntry->setVideoCategory('Autos');// provide your video category - can be any youtube acceptable categories // Set keywords. Please note that this must be a comma-separated string // and that individual keywords cannot contain whitespace $myVideoEntry->SetVideoTags('cars, funny');// your video keywords $tokenHandlerUrl = 'http://gdata.youtube.com/action/GetUploadToken'; $tokenArray = $yt->getFormUploadToken($myVideoEntry, $tokenHandlerUrl); $tokenValue = $tokenArray['token']; $postUrl = $tokenArray['url']; // place to redirect user after upload $nextUrl = 'http://<your host>/<page_name.php>';// url that will be loaded once the user uploads the video to the youtube channel // build the form $form = '<form action="'. $postUrl .'?nexturl='. $nextUrl . '" method="post" enctype="multipart/form-data">'. '<input name="file" type="file"/>'. '<input name="token" type="hidden" value="'. $tokenValue .'"/>'. '<input value="Upload Video File" type="submit" />'. '</form>';

echo $form; if(isset($_GET['status'])) { $youTubeService = new Zend_Gdata_YouTube($httpClient); $feed = $youTubeService->getuserUploads('default'); $message = 'No further status information available yet.'; foreach($feed as $videoEntry) { if ($videoEntry->getVideoId() == $videoId) { // check if video is in draft status try { $control = $videoEntry->getControl(); } catch (Zend_Gdata_App_Exception $e) { print 'ERROR - not able to retrieve control element ' . $e->getMessage(); return; } if ($control instanceof Zend_Gdata_App_Extension_Control) { if (($control->getDraft() != null) && ($control->getDraft()->getText() == 'yes')) { $state = $videoEntry->getVideoState(); if ($state instanceof Zend_Gdata_YouTube_Extension_State) { $message = 'Upload status: ' . $state->getName() . ' ' . $state->getText(); } else { print $message; } } } } } print $message; } ?>

S-ar putea să vă placă și