0

PHP用のyoutube apiを使用して、サーバーから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 の後にステートメントは実行されません。ここに欠けているものはありますか?

4

2 に答える 2

0

HTML フォームを介して動画を送信し、完了後に別のページに自動的にリダイレクトする場合は、ブラウザー ベースのアップロード フローを使用する必要があります。

直接アップロード フローを使用することを主張する場合、それは YouTube API に直接関係するものではないため、質問に対する答えがわかりません。要するに、「任意の PHP 呼び出しを行った後、新しい Web ページにリダイレクトするにはどうすればよいか」ということです。

于 2012-11-01T12:39:11.180 に答える
0

問題を掘り下げたところ、問題は zend/gdata/app.php のメソッド insertentry にあることがわかりました。何らかの理由で

 $returnEntry = new $className($response->getBody());

$response->getBody()は空ではありませんが、失敗しています。とりあえず、 post() の後のコードをコメントアウトし、このメソッドから null を返します。正常に動作し、制御がアプリケーションに戻ります。これがバグなのか、何かが欠けているのかはわかりません。誰かが何が間違っているのかを指摘できれば幸いです。ありがとう。

于 2012-11-05T05:25:11.550 に答える