C# Can';t使用API v3在Youtube上上传视频

C# Can';t使用API v3在Youtube上上传视频,c#,google-api,google-oauth,youtube-data-api,google-api-dotnet-client,C#,Google Api,Google Oauth,Youtube Data Api,Google Api Dotnet Client,我正在尝试将视频自动上传到我的YouTube帐户。下面的代码应该让我登录,然后上传视频 该应用程序显然有效,并表示视频已上传,但没有真正上传视频 static void Main(string[] args) { Console.WriteLine("YouTube Data API: Upload Video"); Console.WriteLine("=============================="); try

我正在尝试将视频自动上传到我的YouTube帐户。下面的代码应该让我登录,然后上传视频

该应用程序显然有效,并表示视频已上传,但没有真正上传视频

static void Main(string[] args)
{
    Console.WriteLine("YouTube Data API: Upload Video");
    Console.WriteLine("==============================");

    try
    {
        new UploadVideo().Run().Wait();
    }
    catch (AggregateException ex)
    {
        foreach (var e in ex.InnerExceptions)
        {
            Console.WriteLine("Error: " + e.Message);
        }
    }

    Console.WriteLine("Press any key to continue...");
    Console.ReadKey();
}

private async Task Run()
{
    UserCredential credential;
    using (var stream = new FileStream("client_secrets.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,
            new FileDataStore($"{Directory.GetCurrentDirectory()}/credentials")
        );
    }

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

    var video = new Video();
    video.Snippet = new VideoSnippet();
    video.Snippet.Title = "Default Video Title";
    video.Snippet.Description = "Default Video Description";
    video.Snippet.Tags = new string[] { "tag1", "tag2" };
    video.Snippet.CategoryId = "22"; // See https://developers.google.com/youtube/v3/docs/videoCategories/list
    video.Status = new VideoStatus();
    video.Status.PrivacyStatus = "public"; // or "private" or "public"
    var filePath = @"C:\Users\Adriano\source\repos\UploadYoutube\output.mp4"; // Replace with path to actual movie file.

    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();
    }
}

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

void videosInsertRequest_ResponseReceived(Video video)
{
    Console.WriteLine("Video id '{0}' was successfully uploaded.", video.Id);
}
这将出现在控制台上

YouTube数据API:上传视频 已发送10485760字节。 已发送20971520字节。 已发送31457280字节。 已发送41943040字节。 已成功上载视频id“XXQGD6ZfYKs”。
按任意键继续…

有几种情况可能会导致您无法找到您的视频,即使它可能需要上传

首先,记住Youtube API是基于频道的,当您授权应用程序时,您选择了一个频道。如果您记不起选择了哪个频道,请确保您正在Youtube中检查此频道最简单的方法是重新授权您的应用程序,将“user”更改为其他内容这将导致代码再次请求授权或进入“{Directory.GetCurrentDirectory()}/credentials”并查找由应用程序创建的凭据文件。删除它,它将再次请求授权


第二个问题可能是你没有检查私人视频。如果应用程序未通过,则通过api上传的YouTube视频将显示为私人视频。

有几种情况可能会导致您无法找到视频,即使视频已被上传

首先,记住Youtube API是基于频道的,当您授权应用程序时,您选择了一个频道。如果您记不起选择了哪个频道,请确保您正在Youtube中检查此频道最简单的方法是重新授权您的应用程序,将“user”更改为其他内容这将导致代码再次请求授权或进入“{Directory.GetCurrentDirectory()}/credentials”并查找由应用程序创建的凭据文件。删除它,它将再次请求授权


第二个问题可能是你没有检查私人视频。如果应用程序未通过api,则通过api上传的YouTube视频将显示为私有。

好的,那么您怎么会认为视频未上传?您是否在私人视频下检查了您的帐户?请记住,YouTube是基于频道的,当您登录时,您选择了一个频道,请检查该频道。另外,请记住,在您的应用程序通过审查过程之前,视频将作为私有文件上载。是的,很抱歉我忘记编辑代码,但已尝试从私有文件更改为公共文件,但频道上说youtube出于某些原因将其设为私有文件。默认情况下,您不了解通过youtube API上载的任何视频都将被禁用在你的应用程序通过谷歌的验证程序之前,它是私有的。那么你的视频会出现在你的频道的私人视频下吗?哦,好吧,对不起,我不知道。我如何进行验证?好的,那么是什么让你认为视频没有上传?您是否在私人视频下检查了您的帐户?请记住,YouTube是基于频道的,当您登录时,您选择了一个频道,请检查该频道。另外,请记住,在您的应用程序通过审查过程之前,视频将作为私有文件上载。是的,很抱歉我忘记编辑代码,但已尝试从私有文件更改为公共文件,但频道上说youtube出于某些原因将其设为私有文件。默认情况下,您不了解通过youtube API上载的任何视频都将被禁用在你的应用程序通过谷歌的验证程序之前,它是私有的。那么你的视频会出现在你的频道的私人视频下吗?哦,好吧,对不起,我不知道。我如何进行验证?您好,我可以看到您在谷歌API方面有很多经验,我有一些疑问和必要的建议,因为我也在谷歌API上工作了很长时间。我们可以加入聊天组吗@DalmTohi在那里,我可以看到你在谷歌API方面有很多经验,我有一些疑问和必要的建议,因为我也在谷歌API工作了很长时间。我们可以加入聊天组吗@达尔姆托