0
我在cakephp上做了一個網站,用戶可以上傳視頻,並且一旦經主持人批准,即可在網站上發佈視頻。目前,我接受正在我的服務器上傳的視頻文件。這些文件將由主持人下載並檢查,如果他們看起來不錯,主持人將點擊一個按鈕,將視頻上傳到YouTube並將鏈接保存到數據庫中。將網站後臺的視頻上傳到YouTube
現在,我正在使用ClientLogin與YouTube進行身份驗證,並嘗試使用Zend Gdata庫上傳視頻。沒有它提供多文檔,我還沒有得到任何錯誤回來,但它不工作:
require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata_YouTube');
Zend_Loader::loadClass('Zend_Gdata_CLientLogin');
Zend_Loader::loadClass('Zend_Gdata_App_Exception');
Zend_Loader::loadClass('Zend_Gdata_App_AuthException');
Zend_Loader::loadClass('Zend_Gdata_App_HttpException');
Zend_Loader::loadClass('Zend_Gdata_YouTube_VideoEntry');
// Define variables
$email = '[email protected]';
$passwd = 'pass';
$applicationId = 'company-app-1.0';
$developerKey = 'AI39si5GGdQnX588uduNxgZL6I_UW32dr43FVH0ehf2jqN3CBIk5PIZHOG1-ag_Q8eaVlWnIxP7fLS3UW5Ofg45MzAxmW4XyAFw';
// Creating a ClientLogin authenticated Http Client
try {
$client = Zend_Gdata_ClientLogin::getHttpClient($email, $passwd, 'cl');
} catch (Zend_Gdata_App_CaptchaRequiredException $cre) {
echo 'URL of CAPTCHA image: ' . $cre->getCaptchaUrl() . "\n";
echo 'Token ID: ' . $cre->getCaptchaToken() . "\n";
} catch (Zend_Gdata_App_AuthException $ae) {
echo 'Problem authenticating: ' . $ae->exception() . "\n";
}
// Passing a Developer Key and ClientID to Zend_Gdata_YouTube
$yt = new Zend_Gdata_YouTube($client, $applicationId, null, $developerKey);
// Uploading a video
$myVideoEntry = new Zend_Gdata_YouTube_VideoEntry();
$filesource = $yt->newMediaFileSource('001.mov');
$filesource->setContentType('video/quicktime');
$filesource->setSlug('001.mov');
$myVideoEntry->setMediaSource($filesource);
$myVideoEntry->setVideoTitle('My Test Movie');
$myVideoEntry->setVideoDescription('My Test Movie');
// Note that category must be a valid YouTube category !
$myVideoEntry->setVideoCategory('Comedy');
// Set keywords, note that this must be a comma separated string
// and that each keyword cannot contain whitespace
$myVideoEntry->SetVideoTags('baby, funny');
// Optionally set some developer tags
/*
$myVideoEntry->setVideoDeveloperTags(array('mydevelopertag', 'anotherdevelopertag'));
*/
// Set Video as Private
$myVideoEntry->setVideoPrivate();
// Upload URI for the currently authenticated user
$uploadUrl = 'http://uploads.gdata.youtube.com/feeds/app/default/uploads';
// Try to upload the video, catching a Zend_Gdata_App_HttpException
// if availableor 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();
}
try {
$control = $videoEntry->getControl();
} catch (Zend_Gdata_App_Exception $e) {
echo $e->getMessage();
}
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) {
print 'Upload status: ' . $state->getName() .' '. $state->getText();
} else {
print 'Not able to retrieve the video status information' .' yet. ' . "Please try again shortly.\n";
}
}
}
哪部分不工作? – ajreal 2010-11-16 16:54:56
這就是我無法弄清楚......因爲我說,我沒有得到任何錯誤或任何輸出。 – 2010-11-16 17:51:41
我不明白爲什麼人們在給我提出反對票的時候,我的問題是非常直截了當的!無論如何,我的問題解決了。顯然,它在我的本地服務器上給了我一個空白屏幕,但它在活動服務器上正常工作。我也沒有將uploadUrl中的默認值更改爲我的用戶名。 – 2010-11-24 18:22:27