我想直接上傳的視頻從服務器使用youtube API for youtube API。上傳的代碼位於控制器中,如下所示: function uploadVideo(){ require_once'Zend/Loader.php';如何使用youtube api直接上傳後重定向
Zend_Loader::loadClass('Zend_Gdata_YouTube');
$yt = new Zend_Gdata_YouTube();
Zend_Loader::loadClass('Zend_Gdata_AuthSub');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
//client login
$authenticationURL = 'https://www.google.com/accounts/ClientLogin';
$httpClient = Zend_Gdata_ClientLogin::getHttpClient($username = '[email protected]', $password = 'password', $service = 'youtube', $client = null, $source = 'videotest',$loginToken = null, $loginCaptcha = null, $authenticationURL);
$developerKey = 'my-key';
$yt = new Zend_Gdata_YouTube($httpClient, "videotest",null,$developerKey);
$myVideoEntry = new Zend_Gdata_YouTube_VideoEntry();
// create a new Zend_Gdata_App_MediaFileSource object
$path = Configure::read('Files.write');
$video = $path . DS . 'videos' . DS .'car.mp4';
$filesource = $yt -> newMediaFileSource($video);
$filesource -> setContentType('video/mp4');
$filesource -> setSlug($video);
// add the filesource to the video entry
$myVideoEntry -> setMediaSource($filesource);
$myVideoEntry -> setVideoTitle('car');
$myVideoEntry -> setVideoDescription('car video');
// The category must be a valid YouTube category!
$myVideoEntry -> setVideoCategory('Autos');
$myVideoEntry -> SetVideoTags('cars, test');
$myVideoEntry -> setVideoDeveloperTags(array('mydevtag', 'anotherdevtag'));
$myVideoEntry->setVideoPrivate();
// upload URI for the currently authenticated user
$uploadUrl = "http://uploads.gdata.youtube.com/feeds/api/users/default/uploads";
try {
$newEntry = $yt -> insertEntry($myVideoEntry, $uploadUrl, 'Zend_Gdata_YouTube_VideoEntry');
echo "returned from youtube";
$this -> redirect('/videos/view');
} catch (Zend_Gdata_App_HttpException $httpException) {
//print_r($httpException);
echo $httpException -> getRawResponseBody();
} catch (Zend_Gdata_App_Exception $e) {
print_r($e);
echo $e -> getMessage();
}
}
的視頻被上傳到我的YouTube頻道,但上傳後,我只看到一個空白的屏幕和它不重定向。事實上它insertentry後不執行任何聲明。這裏有什麼遺漏嗎?
表單中的$ nextUrl後面缺少一個空格,就在method =「post」之前 – janenz00
好吧,我現在編輯它爲$ form =「
「; ..但仍然是空白頁並且沒有重定向 – flowerpot