2013-04-11 3 views
1

YouTube에 동영상을 올리기위한 POC ASP.NET MVC 애플리케이션을 만들고 있습니다. 동영상을 업로드하려고하면 WebException이있는 GDataRequestException이 내부 예외로 표시됩니다.Youtube API를 통해 YouTube에 비디오를 업로드하면 WebException이 발생합니다. - (500) 내부 서버 오류

다음
(500) Internal Server Error. 
The stacktrace of the WebException is: 

    at System.Net.HttpWebRequest.GetResponse() 
    at Google.GData.Client.GDataRequest.Execute() 

내 코드입니다 :

public ActionResult oauth2callback(string code) 
{ 
    if (!string.IsNullOrWhiteSpace(code)) 
    { 
     JObject json; 

     NameValueCollection postData = new NameValueCollection(); 
     postData.Add("code", code); 
     postData.Add("client_id", "The client ID"); 
     postData.Add("client_secret", "The secret code"); 
     postData.Add("redirect_uri", "http://localhost:64896/home/oauth2callback"); 
     postData.Add("grant_type", "authorization_code"); 

     json = JObject.Parse(
      HttpClient.PostUrl(
      new Uri("https://accounts.google.com/o/oauth2/token"), postData)); 
     string accessToken = json["access_token"].ToString(); 
     string refreshToken = json["refresh_token"].ToString(); 
     bool isBearer = 
      string.Compare(json["token_type"].ToString(), 
          "Bearer", 
          true, 
          CultureInfo.CurrentCulture) == 0; 

     var settings = new YouTubeRequestSettings("App name", 
      "API key from simple API access", accessToken); 
     var request = new YouTubeRequest(settings); 

     Video newVideo = new Video(); 
     newVideo.Title = "Test Video"; 
     newVideo.Keywords = "key 1 , key 2"; 

     newVideo.Tags.Add(new MediaCategory("Games", YouTubeNameTable.CategorySchema)); 

     newVideo.Description = "Upload testing"; 
     newVideo.YouTubeEntry.Private = false; 

     newVideo.Private = true; 

     newVideo.YouTubeEntry.MediaSource = new 
      MediaFileSource(@"C:\Users\Kaare\Videos\TestVideo1.avi", "video/x-msvideo"); 

     try 
      { 
       Video createdVideo = request.Upload(newVideo); 
       return View(); 
      }     
      catch (GDataRequestException exp) 
      { 
       //Do something mening full 

      }     
    } 
    else 
    { 
     return RedirectToAction("LoginFail"); 
    } 
} 

너희들의 잘못가는 뭐죠의 어떤 생각을 가지고 있습니까 이것은 내가 가진 메시지입니다?

+0

YouTube에서 동영상을 가져오고, 변경하고 삭제할 수 있습니다. 그래서 그것은 실패한 업로드 일뿐입니다. –

+0

작고 짧은 비디오 파일을 사용해 보셨습니까? 나는 더 길거나 더 큰 파일에 종종 문제가 있었습니까? – Akku

+0

비디오 파일의 크기는 2,63 MB입니다. 그것은 9 sek 걸립니다. 재생할 수 있습니다. 따라서 그다지 크지는 않습니다 :-) –

답변

0

오류 500은 어렵습니다.

자세한 내용이있는 XML 응답을받을 수 있습니까? https://developers.google.com/youtube/2.0/developers_guide_protocol_error_responses

500 개의 응답 코드는 YouTube에서 요청을 처리하는 중 오류가 발생했음을 나타냅니다. 나중에 요청을 다시 시도 할 수 있습니다.

https://developers.google.com/youtube/2.0/reference#Response_Codes

당신이 당신의 OAuth2를 매개 변수로 사용합니까 어떤 범위

? 다른 YouTube 계정을 사용해 보셨습니까? 재개 가능한 업로드를 사용해 볼 수 있습니까?

문제가 될 수있는 유일한 점은 authsub를 사용하기위한 생성자 인 YouTubeRequestSettings()이며 oauth2를 사용하고있는 것입니다. youtube sdk의 소스를 수정하고 액세스 키 대신 oauth2 매개 변수 객체를 사용하는 새로운 YouTubeRequestSettings() 생성자를 추가 할 수 있습니다. 예를 들어 gdata sdk에서 RequestSettings() oauth2 생성자를 볼 수 있습니다.

업로드가 아닌 다른 요청을 할 수는 있지만 문제는 아닙니다.

마지막 아이디어 하나 : request.Service.InsertAsync (new Uri ("http://uploads.gdata.youtube.com/feeds/api/users/default/uploads"), newVideo.AtomEntry, newVideo);