1

私は、ユーザーがビデオをアップロードでき、モデレーターによって承認されるとサイトに公開される、cakephpのサイトを作成しています。現在、サーバーにアップロードされているビデオファイルを受け付けています。これらのファイルはダウンロードされ、モデレーターによってチェックされます。問題がない場合、モデレーターはボタンをクリックして動画をYouTubeにアップロードし、データベースにリンクを保存します。

現在、ClientLoginを使用してYouTubeで認証し、ZendGdataライブラリを使用してビデオをアップロードしようとしています。利用できるドキュメントはあまりなく、エラーも返されませんが、機能しません。

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";
        }
    }
}
4

1 に答える 1

2

どうやら、ローカルサーバーでは空白の画面が表示されていましたが、ライブサーバーでは正常に機能していました。また、uploadUrlのデフォルトを自分のユーザー名に変更していません。

于 2011-04-25T08:46:52.980 に答える