C# 上传视频文件后,如何获取youtube视频链接?

C# 上传视频文件后,如何获取youtube视频链接?,c#,.net,youtube-api,youtube-data-api,google-api-dotnet-client,C#,.net,Youtube Api,Youtube Data Api,Google Api Dotnet Client,这是上载视频文件时发生的事件: 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_E

这是上载视频文件时发生的事件:

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,但是没有link属性或显示链接的东西

这就是我上传视频的方式,但我不确定这是否有助于我在上传完成后找到上传的视频链接

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();
    }
}
在中,上传视频后,有一些代码可以检查我认为是视频的ID:

void videosInsertRequest_ResponseReceived(Video video)
    {
      Console.WriteLine("Video id '{0}' was successfully uploaded.", video.Id);
    }
因此,您应该能够传入
视频
对象并获取其ID

或者,您可以尝试使用并指定上载播放列表ID查看最近上载的视频,然后获取最新视频的ID