【问题标题】:Uploading video from website backend to YouTube将视频从网站后端上传到 YouTube
【发布时间】:2011-05-10 21:24:27
【问题描述】:

我正在 cakephp 中创建一个网站,用户可以在其中上传视频,并且一旦获得版主批准,这些视频就会在网站上发布。目前,我正在接受正在上传到我的服务器上的视频文件。这些文件将由版主下载和检查,如果它们看起来不错,版主将单击一个按钮,将视频上传到 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 = 'myemail@gmail.com';
$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";
        }
    }
}

【问题讨论】:

  • 这是我无法弄清楚的......因为正如我所说,我没有收到任何错误或任何输出。
  • 当我的问题尽可能直截了当时,我不明白为什么人们会给我反对票!无论如何,我的问题解决了。显然,它在我的本地服务器上给了我一个空白屏幕,但它在实时服务器上工作正常。我也没有将uploadUrl中的默认值更改为我的用户名。
  • 是的,我也不明白没有 cmets 的反对票。 +1

标签: php api zend-framework youtube gdata


【解决方案1】:

显然,它在我的本地服务器上给了我一个空白屏幕,但它在实时服务器上工作正常。我也没有将 uploadUrl 中的默认值更改为我的用户名。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-05-09
    • 1970-01-01
    • 2015-09-20
    • 2019-05-21
    • 1970-01-01
    • 1970-01-01
    • 2014-02-20
    • 2013-02-08
    相关资源
    最近更新 更多