2010-11-22 3 views
4

Youtube DataAPI를 사용하여 YouTube 사이트에 동영상을 업로드하려고합니다. the documentation for Browser-based uploading에서 제공되는 예제를 사용하여 기본 예제를 얻을 수 있습니다. 문제는 이것을 jQuery에서 사용할 수있는 메서드로 변환 할 수 없다는 것입니다.YouTube API 및 jQuery를 사용하여 YouTube에 비디오를 업로드하려면 어떻게해야합니까?

내 코드에서 이미 비디오에 대한 메타 데이터 값을 설정하고 데이터 API에서 업로드 할 토큰 값을 받았습니다. 그러나, 내가 업로드를 수행 할 jQuery를 실행하려고하지만, uploads.gdata.youtube.com을 나에게 다음 (피들러의 호의를) 제공 : 여기

HTTP/1.1 404 Not Found 
Server: Upload Server Built on Nov 11 2010 15:36:58 (1289518618) 
Date: Mon, 22 Nov 2010 01:44:58 GMT 
Pragma: no-cache 
Expires: Fri, 01 Jan 1990 00:00:00 GMT 
Cache-Control: no-cache, no-store, must-revalidate 
Content-Length: 0 
Content-Type: text/html 

는 형태입니다. 내가 오프 JQuery와 $("form").submit를 사용하여 호출 발로이기 때문에 동작은 현재 '#'로 설정되어 있지만 내가 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> 

을 여기에 그것을 내가 호출을 실행하기 위해 사용하고 jQuery를 (데이터 토큰 유튜브 포스트 URL을 보유하고 내 서버에서 이전 jQuery를 호출에 의해 반환 된 JSON이며, 값은 성공을 표시하기 위해) :

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); 
         } 
        }); 

마지막을 받고 업로드 된 비디오는 문제의 절반입니다. YouTube가 동영상을 수락/거부하면 브라우저가 nexturl 매개 변수로 리디렉션되고 params를 추가하여 상태를 나타냅니다. jQuery를 통해 이것을 보내면 어떻게 처리 할 수 ​​있습니까?

+0

를? 나는 같은 문제에 부딪치고있다! – Tom

+0

@Tom 클라이언트에서 YouTube로 제대로 작동하지 않았습니다. 우리는 파일을 서버로 옮기고 거기에서 직접 업로드를 수행하기로 결정했습니다. 미래에, 나는 이것을 원래의 아이디어에 더 가까운 것으로 리팩토링하고 싶습니다. – Steven

+0

안녕하세요, 죄송하지만 저는 한 걸음 뒤로 물러나 있습니다. YouTube에 비디오를 업로드하기 위해 PHP 파일을 코딩하려고합니다. 나를 이끌 수 있습니까? 젠드 프레임 워크를 사용했지만 오류가 발생했습니다. http://stackoverflow.com/questions/7628677/accessing-youtube-services-from-php 대체품을 찾고 있습니다. 도와주세요. 어떤 식 으로든 알고 있다면 – shababhsiddique

답변

2

아마도 내가 틀렸을 수도 있지만, AJAX를 통해 파일을 업로드하는 것은 불가능합니다 (보안 문제). 어쩌면 YouTube API가 뭔가를 제공하지만 잘 모르겠습니다. 해결 방법 :

  • (업로드를 시작할 위치) 자체를 만듭니다. id = 'upload_iframe'
  • 업로드 작업을 수행 할 업로드 파일을 만듭니다 (php, asp.net, whatsoever ...);
  • 는 PHP 파일에서 양식 (ID = 'my_form'), 설정 다중/폼 데이터, 설정 대상 = 'upload_iframe'및 설정 작업 = 'upload.php로'

을 만들 upload.php로 당신 업로드 상태를 트리거 할 수도 있습니다. 업로드 실패 (alert ("")), 성공 후 redirec (top.location.href = 'sucess.php') 또는 그와 비슷한 것.

미세 조정 도움이되기를 바랍니다 : 추가로 당신은 필드에 값이 있는지 여부를 확인하는 리스너를 추가하여 수정 업로드 제출 버튼을 가질 수 있습니다. 그렇다면 $ ('# my_form')을 실행하여 업로드를 시작할 수 있습니다. (필요 JQuery와)

이 읽을 수 있습니다 : 당신이 이제까지 해결책을 알아낼나요 http://code.google.com/apis/youtube/2.0/developers_guide_protocol_browser_based_uploading.html#Browser_based_uploading

관련 문제