jquery - YouTube API-通过Ajax上传视频

标签 jquery ajax file-upload youtube youtube-api

我正在使用标准的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/

相关文章:

javascript - 在 javascript 中获取 textext 标签?

javascript - Zombie.js 不执行同步 ajax 请求

JQuery Cycle 和 JSON with JQuery

javascript - 为什么用户选中一个框与以编程方式执行不同?

android - Jquery 移动应用程序奇怪的行为

javascript - 将鼠标悬停在图像上时以受控方式滚动 div 内容

php - 如何验证存储在多个字段中的公司/客户列出的电子邮件?

file-upload - Jenkins Parameterized Build上传文件并保存原文件名

c# - Javascript函数不会立即运行

google-chrome - html 文件上传控件不会在 Chrome 中上传文件