2014-07-14 1 views
3

내가 유튜브 API에 새로 온 사람과 동영상을 업로드 할 mediaBodyRequired지고,하지만 난 insert,업로드 비디오, 오류

fileStream = r.result; 
    var request = gapi.client.youtube.videos.insert({ 
     part: 'snippet, status', 
     resource: { 
      snippet: { 
       title: 'my video', 
       description: 'Description', 
       categoryId: "22" 
      }, 
      status: { 
       privacyStatus: "private" 
      } 
     } 
    }, fileStream); 
    console.log("after request") 
    request.execute(function(response) { 
     var result = response.result; 
     console.log(response); 
     if (result) { 
      console.log("execute completed"); 
     } 
    }); 
} 

을 사용하는 방법을 알고하지 않습니다하지만 오류를 제공합니다 :

domain: "youtube.video" 
location: "body" 
locationType: "other" 
message: "Bad Request" 
reason: "mediaBodyRequired" 

내가 문서 here를 읽을 수 있지만 마녀 속성은 비디오의 몸을 표현 찾지 못했습니다. 누구든지이 문제를 해결하는 방법을 알고 있습니까? 덕분에

답변

1

대부분의 실행 가능한 접근 방식은 자바 클라이언트 라이브러리가 아니라 AJAX를 사용하여 자바 스크립트로 재개 가능한 업로드 프로토콜을 구현하는 것입니다. 재개 가능한 업로드 프로토콜은 먼저 JSON 메타 데이터와 특수 매개 변수가 포함 된 요청을 제출하고 응답의 Location 헤더는 파일 콘텐츠를 업로드 할 보조 URL을 제공한다는 의미입니다.

  • 재개 가능한 업로드 프로토콜이 문서에 권장되며 문서의 다른 코드 샘플 (JS에는없는 코드 샘플)이 사용합니다.

  • API가 "작동 중"인 비 RUP 버전이 있는데 업로드가 처리되지 않습니다.

  • Google 클라이언트 라이브러리를 사용하여 RUP를 구현하려고 시도했으며 첫 번째 단계에서 기본 HTTP 요청/응답이 올바르더라도 응답 객체는 undefined이었습니다.

  • jQuery를 AJAX를 사용하여 RUP를 구현 여기에 샘플 코드가 호출 : https://youtube-api-samples.googlecode.com/git/yt-upload-javascript/index.html

  • API 설명서가 정말 당신이 지금까지 내가 말할 수있는, 특히 자바 스크립트 삽입을하는 방법을 말하지 않는다.

참고 :

https://developers.google.com/youtube/v3/guides/using_resumable_upload_protocol

https://developers.google.com/api-client-library/javascript/dev/dev_jscript

https://developers.google.com/youtube/v3/guides/uploading_a_video

Youtube Video Upload using javascript