我正在尝试使用文档中解释的直接上传方法将视频上传到youtube。
我已经正确地包含了我的开发人员密钥,并且正在毫无问题地获得会话令牌。当它将我引导到带有令牌的上传页面时,问题就会出现。它没有上传并返回视频id,而是向我显示了一行
文件过早结束。
我是zend的新手,也是第一次使用youtube api,我设法解决了身份验证和一些错误,这些错误都显示了出来,但我不知道这个问题是为什么或在哪里。
这是我的php文件
<?php
session_start();
require_once 'Zend/Loader.php'; // the Zend dir must be in your include_path
Zend_Loader::loadClass('Zend_Gdata_YouTube');
Zend_Loader::loadClass('Zend_Gdata_AuthSub');
Zend_Loader::loadClass('Zend_Uri_Http');
function getAuthSubRequestUrl()
{
$next = 'http://localhost/trial/trial.php';
$scope = 'http://gdata.youtube.com';
$secure = false;
$session = true;
return Zend_Gdata_AuthSub::getAuthSubTokenUri($next, $scope, $secure, $session);
}
//generate link if no session or token has been requested
if (!isset($_SESSION['sessionToken']) && !isset($_GET['token'])){
echo '<a href="' . getAuthSubRequestUrl() . '">Login to YouTube API!</a>';
//if token has been requested but not saved to a session then save the new token to a session
} else if (!isset($_SESSION['sessionToken']) && isset($_GET['token'])) {
$_SESSION['sessionToken'] = Zend_Gdata_AuthSub::getAuthSubSessionToken($_GET['token']);
}
if(isset($_SESSION['sessionToken'])) {
$clientLibraryPath = '/library';
$oldPath = set_include_path(get_include_path() . PATH_SEPARATOR . $clientLibraryPath);
$sessionToken = $_SESSION['sessionToken'];
$developerKey = 'my-key-here'; //I have inserted the key correctly.
$httpClient = new Zend_Gdata_HttpClient();
$httpClient->setAuthSubToken($sessionToken);
$yt = new Zend_Gdata_YouTube($httpClient, '23', '234', $developerKey);
$myVideoEntry = new Zend_Gdata_YouTube_VideoEntry();
$file= '../path_to_file/filename.mp4';
$file = realpath($file);
$filesource = $yt->newMediaFileSource($file);
// create a new Zend_Gdata_App_MediaFileSource object
$filesource = $yt->newMediaFileSource('file.mov');
$filesource->setContentType('video/quicktime');
// set slug header
$filesource->setSlug('file.mov');
$myVideoEntry->setVideoTitle('My Test Movie');
$myVideoEntry->setVideoDescription('My Test Movie');
$myVideoEntry->setVideoCategory('Entertainment');
$myVideoEntry->SetVideoTags('testme');
$myVideoEntry->setVideoDeveloperTags(array('tester', 'test'));
$uploadUrl = 'http://uploads.gdata.youtube.com/feeds/api/users/default/uploads';
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();
}
}
?>
谢谢。如果需要,请询问有关问题或代码的进一步解释或信息。
我建议改用数据API,并使用可恢复的上传。下面是一个PHP上传示例。