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(第二行),这是确定的 - 视频也上传。
介意给我们一些代码? –
那么,这里是一个...它只是zend youtube上传 –
http 302,是一个重定向。猜测这与你将数据发布到另一个域的事实有关,这就是为什么它是“红色”来警告XSS可能吗?对不起,我迟到的答案:) –