C# 如何使用c使用Youtube api登录过程?

C# 如何使用c使用Youtube api登录过程?,c#,youtube-api,youtube.net-api,C#,Youtube Api,Youtube.net Api,医生来了。可获得的所以我用 YouTubeRequestSettings settings = new YouTubeRequestSettings("Appname","devkey", textBox1.Text, textBox2.Text); request = new YouTubeRequest(settings); Video newVideo = new Video(); newVideo.Title = "Test"; newVideo.Tags.Add(new MediaC

医生来了。可获得的所以我用

YouTubeRequestSettings settings = new YouTubeRequestSettings("Appname","devkey", textBox1.Text, textBox2.Text);
request = new YouTubeRequest(settings);

Video newVideo = new Video();
newVideo.Title = "Test";
newVideo.Tags.Add(new MediaCategory("Animals", YouTubeNameTable.CategorySchema));
newVideo.Description = "Testing Testing Testing";
newVideo.YouTubeEntry.Private = false;
newVideo.YouTubeEntry.MediaSource = new MediaFileSource("C:\\BabyBoyScenesBackground_PAL.wmv", "video/x-ms-wmv");
try
{
  request.Upload(newVideo);
}
catch (Exception ccc)
{
  MessageBox.Show(ccc.ToString());
}
只是为了得到授权。我需要改变什么。如果你问,我发现的所有来源要么已经过时,要么人们没有处理这个问题


对于Appname,devkey I使用了适当的值以及pw和username。

恐怕在这种情况下,正如401未经授权错误所预期的那样,您提供的详细信息肯定不正确。我不厌其烦地尝试了你的代码,它按预期工作,并上传了视频。您的devkey、pw或用户名必须不正确,或者在上面发布的代码之外一定有问题,因为它对我来说工作正常

但是,您确实应该为此任务使用后台工作人员,可能如下所示:

namespace YouTube
{
    using System;
    using System.ComponentModel;
    using System.Windows;

    using Google.GData.Client;
    using Google.GData.Extensions.MediaRss;
    using Google.GData.YouTube;
    using Google.YouTube;

    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private static BackgroundWorker uploader;

        private static YouTubeRequestSettings settings;

        static void UploaderDoWork(object sender, DoWorkEventArgs e)
        {
            var request = new YouTubeRequest(settings);
            var newVideo = new Video { Title = "Test" };
            newVideo.Tags.Add(new MediaCategory("Animals", YouTubeNameTable.CategorySchema));
            newVideo.Description = "Testing Testing Testing";
            newVideo.YouTubeEntry.Private = true;
            newVideo.YouTubeEntry.MediaSource = new MediaFileSource("C:\\Wildlife.wmv", "video/x-ms-wmv");            
            try
            {
                request.Upload(newVideo);
            }
            catch (Exception exception)
            {
                MessageBox.Show("Upload failed: " + exception.Message);
            }
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            settings = new YouTubeRequestSettings(
                "app",
                "devkey",
                "email",
                "password");
            uploader = new BackgroundWorker { WorkerReportsProgress = true, WorkerSupportsCancellation = true };
            uploader.DoWork += UploaderDoWork;
            uploader.RunWorkerCompleted += delegate { MessageBox.Show("Upload completed!"); };
            uploader.RunWorkerAsync();
            MessageBox.Show("Initiated upload...");
        }
    }
}

希望你能解决

恐怕在这种情况下,正如401未经授权的错误所预期的那样,您一定给出了错误的详细信息。我不厌其烦地尝试了你的代码,它按预期工作,并上传了视频。您的devkey、pw或用户名必须不正确,或者在上面发布的代码之外一定有问题,因为它对我来说工作正常

但是,您确实应该为此任务使用后台工作人员,可能如下所示:

namespace YouTube
{
    using System;
    using System.ComponentModel;
    using System.Windows;

    using Google.GData.Client;
    using Google.GData.Extensions.MediaRss;
    using Google.GData.YouTube;
    using Google.YouTube;

    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private static BackgroundWorker uploader;

        private static YouTubeRequestSettings settings;

        static void UploaderDoWork(object sender, DoWorkEventArgs e)
        {
            var request = new YouTubeRequest(settings);
            var newVideo = new Video { Title = "Test" };
            newVideo.Tags.Add(new MediaCategory("Animals", YouTubeNameTable.CategorySchema));
            newVideo.Description = "Testing Testing Testing";
            newVideo.YouTubeEntry.Private = true;
            newVideo.YouTubeEntry.MediaSource = new MediaFileSource("C:\\Wildlife.wmv", "video/x-ms-wmv");            
            try
            {
                request.Upload(newVideo);
            }
            catch (Exception exception)
            {
                MessageBox.Show("Upload failed: " + exception.Message);
            }
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            settings = new YouTubeRequestSettings(
                "app",
                "devkey",
                "email",
                "password");
            uploader = new BackgroundWorker { WorkerReportsProgress = true, WorkerSupportsCancellation = true };
            uploader.DoWork += UploaderDoWork;
            uploader.RunWorkerCompleted += delegate { MessageBox.Show("Upload completed!"); };
            uploader.RunWorkerAsync();
            MessageBox.Show("Initiated upload...");
        }
    }
}

希望你能解决

YouTube RequestSettings中是否缺少clientId参数,或者此方法是否有重载?Google.YouTube.YouTube RequestSettings不包含接受5个参数(包括clientId)的构造函数。实际上,没有构造函数包含clientid了。我听说它已弃用。它需要clientId参数。它不需要客户ID。试试看,你会发现。你是在YouTuberRequestSettings中缺少clientId参数,还是此方法有重载?Google.YouTube.YouTuberRequestSettings不包含包含包含clientId的5个参数的构造函数。实际上,没有构造函数包含clientid了。我听说它已弃用。它需要clientId参数。它不需要客户ID。尝试一下,你会看到。一个补充:当试图用var request=new YouTubeRequestsettings替换视频评论时;var newVideo=新视频;newVideo.VideoId=59y0rPq79CM;注释c=新注释;c、 内容=有趣;请尝试{request.AddCommentnewVideo,c;}捕获异常fff{MessageBox.Showfff.ToString;throw;}注释不会显示。想法?根据本api,以下内容已详细说明:一个补充:当试图通过替换为var request=new YouTubeRequestsettings来评论视频时;var newVideo=新视频;newVideo.VideoId=59y0rPq79CM;注释c=新注释;c、 内容=有趣;请尝试{request.AddCommentnewVideo,c;}捕获异常fff{MessageBox.Showfff.ToString;throw;}注释不会显示。想法?根据本api,以下内容已详细说明: