1

답변을 찾지 못했습니다. 모든 해결책을 찾지 못했습니다. YouTube 데이터 v3에서 YouTube 채널로 비디오를 업로드하는 중 예외가 발생합니다. 설치된 응용 프로그램의 키를 만들었습니다. 비디오 타이틀 및 세부 사항까지도 잘 업로드됩니다. 유일한 문제는 예외가 발생한다는 것입니다.Youtube 데이터 api v3 동영상 업로드 오류

작업이 취소되었습니다. 자세한 내용은 끝에 스택 추적을 참조하십시오.

여기 내 코드

private async Task Run() 
    { 
     UserCredential credential; 
     using (var stream = new FileStream("client_secret_766914936775-1ak2tk5e3u0krlbuu9rdip1sfa9u8k44.apps.googleusercontent.com.json", FileMode.Open, FileAccess.Read)) 
     { 
      credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
       GoogleClientSecrets.Load(stream).Secrets, 
       // This OAuth 2.0 access scope allows an application to upload files to the 
       // authenticated user's YouTube channel, but doesn't allow other types of access. 
       new[] { YouTubeService.Scope.YoutubeUpload }, 
       "techno.1", 
       CancellationToken.None 
      ); 
     } 

     YouTubeService youtubeService = new YouTubeService(new BaseClientService.Initializer() 
     { 
      HttpClientInitializer = credential, 
      ApplicationName = "techno ", 

     }); 



     var video = new Video(); 
     video.Snippet = new VideoSnippet(); 
     video.Snippet.Title = "Default Video Title"; 
     video.Snippet.Description = "Default Video Description"; 
     video.Snippet.Tags = new string[] { "tag1", "tag2" }; 
     video.Snippet.CategoryId = "22"; // See https://developers.google.com/youtube/v3/docs/videoCategories/list 
     video.Status = new VideoStatus(); 
     video.Status.PrivacyStatus = "unlisted"; // or "private" or "public" 
     var filePath = @"abc.mp4"; // Replace with path to actual movie file. 

     using (var fileStream = new FileStream(filePath, FileMode.Open)) 
     { 
      var videosInsertRequest = youtubeService.Videos.Insert(video, "snippet,status", fileStream, "video/*"); 
      videosInsertRequest.ProgressChanged += videosInsertRequest_ProgressChanged; 
      videosInsertRequest.ResponseReceived += videosInsertRequest_ResponseReceived; 

      await videosInsertRequest.UploadAsync(); 
     } 
    } 

    private void videosInsertRequest_ProgressChanged(Google.Apis.Upload.IUploadProgress progress) 
    { 
     switch (progress.Status) 
     { 
      case UploadStatus.Uploading: 
       Console.WriteLine("{0} bytes sent.", progress.BytesSent); 
       break; 

      case UploadStatus.Failed: 
       Console.WriteLine("An error prevented the upload from completing.\n{0}", progress.Exception); 
       break; 
     } 
    } 

    private void videosInsertRequest_ResponseReceived(Video video) 
    { 
     Console.WriteLine("Video id '{0}' was successfully uploaded.", video.Id); 
    } 
} 

내가 uploadStatus.Failed videosInsertRequest_ProgressChange 방법을 얻고있다.

는 이미 코드를 사용하려고

youtubeService.HttpClient.Timeout = TimeSpan.FromMinutes (60);

하지만 시간 제한 속성을 사용할 수 없습니다. 그것만 얻는다. 마침내

An error prevented the upload from completing. System.Threading.Tasks.TaskCanceledException: A task was canceled.
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.ConfiguredTaskAwaitable 1.ConfiguredTaskAwaiter.GetResult() at Google.Apis.Upload.ResumableUpload 1.d__94.MoveNext() in C:\Apiary\v1.20\google-api-dotnet-client\Src\Support\GoogleApis\Apis[Media]\Upload\ResumableUpload.cs:line 652 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.ConfiguredTaskAwaitable 1.ConfiguredTaskAwaiter.GetResult() at Google.Apis.Upload.ResumableUpload 1.d__91.MoveNext() in C:\Apiary\v1.20\google-api-dotnet-client\Src\Support\GoogleApis\Apis[Media]\Upload\ResumableUpload.cs:line 581 Error: A task was canceled.

+0

JSON 파일을 다운로드하는이 [SO 스레드] (http://stackoverflow.com/a/27744211/5832311)에서 다른 제안을 시도해 볼 수 있습니다. JSON 파일 이름을'client_secrets.json'으로 바꾼 다음 bin/Debug ot bin/Release와 동일한 * .exe로 디렉토리에 저장하십시오. 또한이 [관련 문제] (https://github.com/youtube/api-samples/issues/7)에 설명 된대로 네트워크 속도가 느린 경우 일 수 있습니다. – abielita

+0

bin/Release에이 파일의 이름을 바꾸고 배치했지만 작동하지 않았습니다. –

답변

0

시간 초과 값으로 15 분이 길다. 나는 1 분을 사용한다.

youtubeService.HttpClient.Timeout = TimeSpan.FromMinutes(1); 

실제 문제는 반환 된 오류를 처리하지 않고 업로드를 다시 시작한다는 것입니다. 샘플 프로그램 "ResumeableUpload.CS.Sample"(https://github.com/google/google-api-dotnet-client-samples )을 참조하십시오. 샘플 프로그램은 동일한 인스턴스에서 오류가 발생한 후 업로드를 다시 시작하고 프로그램을 다시 시작하면 업로드를 다시 시작하는 방법을 보여줍니다.

업로드 시간이 단축되고 코드가 업로드를 다시 시작하면 업로드 서버가 사용 중일 때 업로드 속도가 훨씬 빨라집니다.

+0

네가 옳다. 하지만 동시에 여러 스레드를 업로드하기를 원합니다. IUploadSessionData에서 여러 프로세스에 대해 db로 저장해야하는 uploaduri의 속성을 알려주실 수 있습니까? –

+0

Upload Uri의 모든 속성을 이력서 데이터베이스에 저장하고 싶지 않습니다. –

+0

GitHub에서 샘플 프로그램을 살펴보아야합니다. ** UploadUri.AbsoluteUri **와 파일 업로드의 전체 경로 이름을 저장합니다. –

0

, 그것은 내가 잘못 방법으로 시간 범위를주고 있었다

youtubeService.HttpClient.Timeout = TimeSpan.FromMinutes(15.00); 

을했다.