2

这是当视频文件上传的事件:我用了一个破发点如何在视频文件上传后获得YouTube视频链接?

public static TimeSpan time = new TimeSpan(); 
Video objects = null; 

private void videosInsertRequest_ResponseReceived(Video obj) 
{ 
    System.Timers.Timer aTimer; 
    aTimer = new System.Timers.Timer(); 
    aTimer.Elapsed += aTimer_Elapsed; 
    aTimer.Interval = 10000; 
    aTimer.Enabled = false; 
    uploadstatus = obj.Status.UploadStatus; 
    if (uploadstatus == "uploaded") 
    { 
     fileuploadpercentages = 100; 
     stopwatch.Stop(); 
     var milliseconds = stopwatch.ElapsedMilliseconds; 
     time = stopwatch.Elapsed; 
     time = TimeSpan.FromSeconds(Math.Round(time.TotalSeconds)); 
     uploadstatus = "file uploaded successfully"; 
     string[] lines = File.ReadAllLines(userVideosDirectory + "\\UploadedVideoFiles.txt"); 
     File.WriteAllLines(userVideosDirectory + "\\UploadedVideoFiles.txt", lines.Skip(1)); 
     if (Form1.uploadedFilesList.Count > 0) 
      Form1.uploadedFilesList.RemoveAt(0);     
    } 
    if (uploadstatus == "Completed") 
    { 

    } 

    objects = obj; 
} 

,我看到该变量OBJ有一些性质其中之一就是ID。但没有链接属性或显示链接的内容。

这就是我上传视频的方式,但我不确定它是否会帮助我需要在上传完成后找到上传的视频链接。

private void UploadVideo(string FileName, string VideoTitle, string VideoDescription) 
{ 
    try 
    { 
     var youtubeService = new YouTubeService(new BaseClientService.Initializer() 
     { 
      HttpClientInitializer = credential, 
      ApplicationName = Assembly.GetExecutingAssembly().GetName().Name 
     }); 

     video.Snippet = new VideoSnippet(); 
     video.Snippet.Title = VideoTitle; 
     video.Snippet.Description = VideoDescription; 
     video.Snippet.Tags = new string[] { "tag1", "tag2" }; 
     video.Status = new VideoStatus(); 
     video.Status.PrivacyStatus = "public"; 
     using (var fileStream = new FileStream(FileName, FileMode.Open)) 
     { 

      const int KB = 0x400; 
      var minimumChunkSize = 256 * KB; 

      var videosInsertRequest = youtubeService.Videos.Insert(video, 
       "snippet,status", fileStream, "video/*"); 
      videosInsertRequest.ProgressChanged += videosInsertRequest_ProgressChanged; 
      videosInsertRequest.ResponseReceived += videosInsertRequest_ResponseReceived; 
      // The default chunk size is 10MB, here will use 1MB. 
      videosInsertRequest.ChunkSize = minimumChunkSize * 3; 
      dt = DateTime.Now; 
      totalBytes = fileStream.Length; 
      videosInsertRequest.Upload(); 
     } 
    } 
    catch (Exception errors) 
    { 
     string errorss = errors.ToString(); 
    } 
} 

回答

0

.net sample,视频上传后有一些代码来检查什么,我相信是该视频的ID:

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

所以,你应该能够在你的video对象传递和获取其ID。

或者,您可以尝试使用playlists.list()来查看您最近上传的内容,并指定上传的播放列表ID,然后获取最新视频的ID。