无法在c#中删除YouTube API中的视频

时间:2015-10-05 07:53:22

标签: c# youtube youtube-data-api

我会提前道歉,可能会遗漏一些明显的东西,但我一直在努力寻找关于v3 youtube API的.NET c#实现的充分文档。我正在尝试删除我在等待一分钟后上传的ID中删除的视频。这纯粹是出于测试目的,因为最终软件需要复杂得多,但我已将此问题简化为以下代码。上传运行完美,但最后的删除调用抛出了403. id字符串是正确的,它正在使用,因为我已经尝试了API测试页面上的界面。任何想法或想法都会有所帮助。提前感谢一堆

UserCredential credential;

            credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
                new ClientSecrets
                {
                    ClientId = "id",
                    ClientSecret = "secret"
                },

                new[] { YouTubeService.Scope.YoutubeForceSsl },
                "email",
                CancellationToken.None
            );

        var youtubeService = new YouTubeService(new BaseClientService.Initializer()
        {
            HttpClientInitializer = credential,
            ApplicationName = Assembly.GetExecutingAssembly().GetName().Name
        });
        var video = new Video();
        video.Snippet = new VideoSnippet();
        video.Snippet.Title = "test video";
        video.Snippet.Description = "Default Video Description";
        video.Snippet.Tags = new string[] { "tag1", "tag2" };
        video.Snippet.CategoryId = "28"; 
        video.Status = new VideoStatus();
        video.Status.PrivacyStatus = "unlisted"; 
        var filePath = "path";
        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();
        }

        // uploadID is set globally by response and is correct
        Console.WriteLine(uploadID);

        Thread.Sleep(60000);

        youtubeService.Videos.Delete(uploadID).Execute();

0 个答案:

没有答案