Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/409.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/88.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使用YouTube API和jQuery将视频上传到YouTube?_Javascript_Jquery_Ajax_Youtube Api - Fatal编程技术网

Javascript 如何使用YouTube API和jQuery将视频上传到YouTube?

Javascript 如何使用YouTube API和jQuery将视频上传到YouTube?,javascript,jquery,ajax,youtube-api,Javascript,Jquery,Ajax,Youtube Api,我正在尝试使用Youtube DataAPI将视频上传到我们网站的Youtube帐户。我一直在使用中提供的示例,我能够使基本示例发挥作用。问题是我似乎无法将其转换为一种可以与jQuery一起使用的方法 在我的代码中,我已经为视频设置了元数据值,并从数据API接收了上传的令牌值。但是,当我尝试执行jQuery进行上传时,uploads.gdata.youtube.com会给我以下信息(由Fiddler提供): 这是表格。该操作当前设置为“#”,因为我正在使用$(“form”).submit启动JQ

我正在尝试使用Youtube DataAPI将视频上传到我们网站的Youtube帐户。我一直在使用中提供的示例,我能够使基本示例发挥作用。问题是我似乎无法将其转换为一种可以与jQuery一起使用的方法

在我的代码中,我已经为视频设置了元数据值,并从数据API接收了上传的令牌值。但是,当我尝试执行jQuery进行上传时,uploads.gdata.youtube.com会给我以下信息(由Fiddler提供):

这是表格。该操作当前设置为“#”,因为我正在使用
$(“form”).submit启动JQuery调用,但我不确定正确的操作应该是什么,因为我想通过AJAX完成所有操作:

<form action="#" method="post" name="video_upload" enctype="multipart/form-data">           

<div class="field-group">
    <label style="margin-top:0px" for="video_name">video title</label>
    <input type="text" value="" class="required" tabindex="1" name="video_name" id="video_name">
    <div id="video_name_status"></div>
</div>
<div class="field-group">
    <label for="video_description">description</label>                       
    <textarea class="required" tabindex="2" name="video_description" rows="5" cols="40" id="video_description"></textarea>
    <div id="video_description_status"></div>

</div>                  
<div class="field-group">
    <label for="video_path">video file</label>
    <input  type="file" value="" class="required" tabindex="3" name="video_path" id="video_path">
    <div id="video_status"></div>
</div>

<div id="form-button-group">
    <input type="submit" value="Upload Video" name="submit" id="signup-button">                     
</div>


<div class="youtube-disclaimer">
By clicking 'Upload Video' you certify that you own all rights to the content or that you are authorized by the owner to 
make the content publicly available on YouTube, and that it otherwise complies with the YouTube Terms of Service located 
at <a href="http://www.youtube.com/t/terms">http://www.youtube.com/t/terms</a>.
</div>
</form>

最后,上传视频是问题的一半;一旦YouTube接受/拒绝视频,它应该将浏览器重定向到nexturl参数并附加参数以指示状态。如果我通过jQuery发送,我该如何处理

也许我错了,但是不可能通过AJAX上传文件(出于安全考虑);但也许YouTube API确实提供了一些东西,我不知道?!。解决方法:

  • 创建一个iframe(您将在这里启动上载);id='upload\u iframe'
  • 创建上传文件来完成上传工作(php、asp.net等等);upload.php
  • 创建一个表单(id='my'u form'),设置多部分/表单数据,设置target='upload\u iframe'和set action='upload.php'
在php文件中,您还可以触发上载状态,例如上载失败(警报(“”)、成功后重拨(top.location.href='suces.php')或类似的情况

希望能有帮助

微调: 此外,还可以通过添加侦听器来修改upload field按钮,以检查字段是否有值。如果是,您可以通过触发$(“#我的表单”).submit()触发上载;(需要jquery)

您可以阅读以下内容:

你有没有想出解决办法?我遇到了同样的问题@从客户端到YouTube,Tom从来没有让它正常工作过。我们决定将文件移动到服务器并从那里执行直接上传。在未来,我想把它重构成更接近原始想法的东西。你好,对不起,我比你落后了一步,我正在尝试编写一个php文件,将视频上传到youtube。你能带我走吗?我尝试使用zend框架,但出现了错误。寻找替代品。请帮忙。如果你知道的话
<form action="#" method="post" name="video_upload" enctype="multipart/form-data">           

<div class="field-group">
    <label style="margin-top:0px" for="video_name">video title</label>
    <input type="text" value="" class="required" tabindex="1" name="video_name" id="video_name">
    <div id="video_name_status"></div>
</div>
<div class="field-group">
    <label for="video_description">description</label>                       
    <textarea class="required" tabindex="2" name="video_description" rows="5" cols="40" id="video_description"></textarea>
    <div id="video_description_status"></div>

</div>                  
<div class="field-group">
    <label for="video_path">video file</label>
    <input  type="file" value="" class="required" tabindex="3" name="video_path" id="video_path">
    <div id="video_status"></div>
</div>

<div id="form-button-group">
    <input type="submit" value="Upload Video" name="submit" id="signup-button">                     
</div>


<div class="youtube-disclaimer">
By clicking 'Upload Video' you certify that you own all rights to the content or that you are authorized by the owner to 
make the content publicly available on YouTube, and that it otherwise complies with the YouTube Terms of Service located 
at <a href="http://www.youtube.com/t/terms">http://www.youtube.com/t/terms</a>.
</div>
</form>
if (data.success == true){

                 $.ajax({
                       async : false,
                       type: "POST",
                       url: data.postUrl + "?nexturl=www.mysite.local",                        
                       data: ({file : $('#video_path'),
                               token : data.tokenValue,
                               alt : 'json-in-script'}),
                       contentType : 'multipart/form-data',
                       processData: false,
                       datatype: 'jsonp',
                       jsonpCallback: 'processVideoResponse',
                       success: function(data){
                            alert("success alert" + data);

                       },
                       error: function(data){
                           alert("error" + data);
                       }
                   });