1

这个文档。可用的。所以我用

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

只是为了获得401未经授权。我需要改变什么。如果你问,我发现的所有资源要么已经过时,要么人们没有处理这个问题。

对于“Appname”、“devkey”,我使用了适当的值以及 pw 和用户名。

4

1 回答 1

4

恐怕在这种情况下,正如预期的 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...");
        }
    }
}

希望你能解决!

于 2012-05-25T19:06:46.770 回答