2012-08-23 245 views
0

我使用標準的Zend Youtube庫將視頻上傳到Youtube。它運行良好,但是我需要上傳者在不刷新的情況下工作。Youtube API - 通過ajax上傳視頻

我試圖實現,但我總是得到:從YouTube 302找到響應上傳網址, 400失蹤令牌被送到我的腳本

方法創建上傳

public static function showUploadForm($presenter, $id, $name, $comment) { 

    $yt = self::getYt(); // these are the account settings 

    // create a new VideoEntry object 
    $myVideoEntry = new Zend_Gdata_YouTube_VideoEntry(); 

    $myVideoEntry->setVideoTitle($name); 
    $myVideoEntry->setVideoDescription($comment); 
    // The category must be a valid YouTube category! 
    $myVideoEntry->setVideoCategory('People'); 

    // Set keywords. Please note that this must be a comma-separated string 
    // and that individual keywords cannot contain whitespace 
    $myVideoEntry->SetVideoTags('hockey'); 

    $tokenHandlerUrl = 'http://gdata.youtube.com/action/GetUploadToken'; 
    $tokenArray = $yt->getFormUploadToken($myVideoEntry, $tokenHandlerUrl); 
    $tokenValue = $tokenArray['token']; 
    $postUrl = $tokenArray['url']; 

    // place to redirect user after upload 
    $nextUrl = $presenter->link('//User:videoUploaded', array('id' => $id)); //framework action 


    // build the form 
    $form = '<form id="youtubeUploader" class="ajaxSetVideoData" action="' . $postUrl . '?nexturl=' . $nextUrl . 
      '" method="post" enctype="multipart/form-data">' . 
      '<input id="file" name="file" type="file" />' . 
      '<input name="submit" type="submit" value="send" />' . 
      '<input name="token" type="hidden" value="' . $tokenValue . '"/>'. 
      '</form>' . 
      '<br />'; 
    return $form; 
} 

非常感謝。

編輯:我發現只有輸入「token」作爲參數發送到youtube URL。

EDIT2:AJAX和文件上傳存在問題。有這個插件它的工作: http://malsup.com/jquery/form/#code-samples

但現在仍然得到302兩個腳本中找到,但在URL中的「狀態」是200(第二行),這是確定的 - 視頻也上傳。 enter image description here

+0

介意給我們一些代碼? –

+0

那麼,這裏是一個...它只是zend youtube上傳 –

+0

http 302,是一個重定向。猜測這與你將數據發佈到另一個域的事實有關,這就是爲什麼它是「紅色」來警告XSS可能嗎?對不起,我遲到的答案:) –

回答