English 中文(简体)
如何使用 Youtube api 登录程序使用 c#?
原标题:How to use the Youtube api login procedure using c#?

有 < a href=> "https:// developmenters.google.com/youtube/2.0/ Developers_guide_dotnet#ClientLogin_for_Insalled_Applications" rel=“nofol” > this doc. 可用。 所以我使用了这个 doc.

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 和 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...");
        }
    }
}

希望你解决它了!

问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签