2016-03-29 34 views
0

Youtube yükleme verisi api kullanarak videoyu yüklemek istiyorum ancak maalesef videoyu yüklemeye çalıştığımda, kodumda bir Görev İptal Edildi await videosInsertRequest.UploadAsync(); errot'u oluşturdum zaten AsyncTimeout benim eylem"Görev İptal edildi" HTTP İstemcisi varsayılan zaman aşımı değeri

[AsyncTimeout(3600000)] 
public async Task <ActionResult> YouTube(int? Id) 
{ 
    // await Run(); 
    var dbListVideos = db.Videos.Where(v => v.Id == Id).ToList(); 
    await YouTubeHandler.UploadVideos(dbListVideos); 
    return View(); 
} 

o ı ASP ve zaman uyumsuz Görev

yeni olduğum gibi

public static async Task UploadVideos(List<MyVideo> videosList) 
    { 
     foreach (var vid in videosList) 
     { 
      await Upload(vid); 
     } 
    } 
    public static async Task Upload(MyVideo newVideo) 
    { 
     UserCredential credential; 
     using (var stream = new FileStream("G:\\client_secret_783534382593-0cn4gm229raqq97kdu0ghsj9hqfsc5o1.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 }, 
       "user", 
       CancellationToken.None 
      ); 
     } 

     var youtubeService = new YouTubeService(new BaseClientService.Initializer() 
     { 
      HttpClientInitializer = credential, 
      ApplicationName = Assembly.GetExecutingAssembly().GetName().Name 
     }); 



      Video video = new Video(); 
      video.Snippet = new VideoSnippet(); 
      video.Snippet.Title = newVideo.Title; 
      video.Snippet.Description = newVideo.Description; 
      video.Snippet.Tags = new string[] { newVideo.Tags }; 
      video.Snippet.CategoryId = newVideo.Category; // See https://developers.google.com/youtube/v3/docs/videoCategories/list 
      video.Status = new VideoStatus(); 
      video.Status.PrivacyStatus = newVideo.PrivacyStatus; // or "private" or "publi 
      var filePath = newVideo.Path; // Replace with path to actual movie file. 


     // YouTubeHandler t = new YouTubeHandler(); 
     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(); 
      } 
     } 


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

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

kimse bana lütfen yardımcı Can YouTube API çağırır öznitelik uygulamak zorunda

+1

Bu cevaba bir göz atın: http://stackoverflow.com/a/35008208/1129995 YouTubeService.HttpClient.Timeout – Zaki

+0

için zaman aşımı ayarlamayı deneyin, ancak bu cevaba bakın ama bana yardımcı olmayın! –

+1

Olası kopyası [YouTube API yüklemesi "Bir görev iptal edildi"] (http://stackoverflow.com/questions/34249180/youtube-api-upload-a-task-was-cancelled) – DaImTo

cevap

3

Bu sorunun çözümünü buldum Servis kullanımdan önce zaman aşımını ayarlamanız gerekiyor. bu, görevi iptal edilen sorunu çözecektir.

İlgili konular