2016-04-05 8 views
2

Ich benutze C#, ich kann Video youtube meinen Kanal erfolgreich hochladen. Jetzt möchte ich Video include thumbnail hochladen. Ich habe keine Fehler im Debug aber das Miniaturbild lud nicht, hier ist mein Code:Kann ich Youtube Video und Thumbnail gleichzeitig hochladen?

private static async Task Upload(FileInfo Vidf) 
    { 
     //2.1 Get credentials 
     UserCredential credentials; 

     //2.1.1 Use https://console.developers.google.com/ to get the json file (Credential section) 
     using (var stream = new FileStream(APIjson, FileMode.Open, FileAccess.Read)) 
     { 
      credentials = await GoogleWebAuthorizationBroker.AuthorizeAsync(
       GoogleClientSecrets.Load(stream).Secrets, 
       new[] { YouTubeService.Scope.YoutubeUpload }, 
       "user", 
       CancellationToken.None); 
     } 

     //2.2 Create a YoutubeService instance using our credentials 
     var youtubeService = new YouTubeService(new BaseClientService.Initializer() 
     { 
      HttpClientInitializer = credentials, 
      ApplicationName = Assembly.GetExecutingAssembly().GetName().Name 
     }); 


     //2.3 Create a video object 
     var video = new Video() 
     { 
      Id = Vidf.Name, 
      Status = new VideoStatus 
      { 
       PrivacyStatus = "private" 
      }, 
      Snippet = new VideoSnippet 
      { 
       Title = "...", 
       Description = "...", 
      } 
     }; 

     var filePath = Vidf.FullName; 
     filesize = Vidf.Length; 
     //2.4 Read and insert the video in youtubeService 
     using (var fileStream = new FileStream(filePath, FileMode.Open)) 
     { 
      var videosInsertRequest = youtubeService.Videos.Insert(video, "snippet,status", fileStream, "video/*"); 
      videosInsertRequest.ProgressChanged += ProgressChanged; 
      videosInsertRequest.ResponseReceived += ResponseReceived; 

      //2.4.1 Wait for the upload process 
      await videosInsertRequest.UploadAsync(); 
     } 


     var tpath = Vidf.FullName.Replace("mp4", "jpg"); 

     using (var tStream = new FileStream(tpath, FileMode.Open)) 
     { 
      var tInsertRequest = youtubeService.Thumbnails.Set(video.Id, tStream, "image/jpeg"); 
      tInsertRequest.ProgressChanged += ProgressChanged; 

      await tInsertRequest.UploadAsync(); 
     } 

    } 

Do i Video hochzuladen ersten und fertig youtube warten, um die Videoverarbeitung. Dann laden Thumbnails wie Beispielcode in diesem Link https://developers.google.com/youtube/v3/docs/thumbnails/set#examples

+0

Ich habe diesen Fehler erhalten https://picasaweb.google.com/lh/photo/dRjgLlIS1Kyd-cST-h7-jkzD0UGBzob7Vodjzm8Pv-Q. Also muss dieser Mittelwert zuerst hochgeladen werden und warten, bis youtube alle Aufgabe beendet hat. Dann lade das Thumbnail hoch, oder? – Sicay

Antwort

1

eine globale var "VidID" erstellen und Wert in ResponseReceived Funktion

static void ResponseReceived(Video video) 
    { 
     VidID = video.Id; 
    } 

sollte Video-ID und dann schreibt Thumbnail mit der Video-ID erhalten.