我正在尝试使用 youtube api for PHP 将视频从服务器直接上传到 youtube。上传代码在控制器中,如下所示 function uploadVideo() { require_once 'Zend/Loader.php';
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 = 'myusername@gmail.com', $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 后没有执行任何语句。这里有什么遗漏吗?