如何使用youtube api上传带有旁边频道的YouTube视频 - C#

时间:2017-01-01 19:43:11

标签: c# winforms api youtube youtube-api

我使用YouTube的API上传视频。但是,我的YouTube帐户有两个频道,我只能成功上传到主频道,而不是第二频道。

有谁能告诉我上传到第二个频道需要做什么?

enter image description here

守则:

    private async Task Run(String title,String mota,String[] tag,String filepath)
    {
        UserCredential credential;

        using (var stream = new FileStream("client_secrets.json", FileMode.Open, FileAccess.Read))
        {
            credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
                GoogleClientSecrets.Load(stream).Secrets,                 
                new[] { YouTubeService.Scope.YoutubeUpload},
                "user",
                CancellationToken.None
            );
        }

        var youtubeService = new YouTubeService(new BaseClientService.Initializer()
        {

            HttpClientInitializer = credential,
            ApplicationName = Assembly.GetExecutingAssembly().GetName().Name
        });


        var video = new Google.Apis.YouTube.v3.Data.Video();

        video.Snippet = new VideoSnippet();
        video.Snippet.Title = title;
        video.Snippet.Description = mota;
        video.Snippet.Tags = tag;

        video.Snippet.CategoryId = "22"; 
        video.Status = new VideoStatus();
        video.Status.PrivacyStatus = "unlisted";

        var filePath = filepath;
        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();
        }
    }

1 个答案:

答案 0 :(得分:0)

您必须在OAuth流程中授权正确的帐户。如果红色圈出的第二个帐户是CMS帐户,则必须在API调用中使用onBehalfOfContentOwner参数。有些通话还有forUsername参数,允许您通过提供用户名代表用户拨打电话。

例如,channels.list mehtod同时包含onBehalfOfContentOwner参数和forUsername参数。