0

我正在尝试使用文档中解释的直接上传方法将视频上传到 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();

    }
}
?>

谢谢。如果需要,请询问有关问题或代码的进一步解释或信息。

4

1 回答 1

1

我建议改用数据 API 并利用可恢复上传。这是一个 PHP 上传示例

于 2013-08-29T18:32:52.777 回答