我正在使用标准 Zend Youtube 库将视频上传到 Youtube。它运行良好,但我需要上传程序无需刷新即可工作。
我试图实现它,但我总是得到: 302 Found response from youtube upload url, 400 Missing token was sent to my script
创建上传器的方法
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;
}
提前非常感谢。
编辑:我发现只有输入“令牌”作为参数发送到 youtube URL。
EDIT2:AJAX 和文件上传有问题。有了这个插件,它就可以工作了:http: //malsup.com/jquery/form/#code-samples
但是现在在两个脚本中仍然得到 302 Found,但是 URL 中的“状态”是 200(第二行),这没关系 - 视频也上传了。