我正在使用标准的Zend Youtube库将视频上传到Youtube。运作良好,但我需要上载器才能正常运作。
我试图实现它,但是我总是得到:
302在youtube上传网址中找到响应,
400缺少 token 已发送到我的脚本
创建上传器的方法
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 Found,但是URL中的“状态”为200(第二行),可以,可以上传视频。
最佳答案
AJAX和文件上传存在问题。使用此插件可以正常工作:
http://malsup.com/jquery/form/#code-samples
已解决:解决方案是您应该将IFRAME用作异步上传。看这里:
Youtube IFRAME uploader
关于jquery - YouTube API-通过Ajax上传视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12094406/