作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这是我在 form1 中的代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using Google.GData.Client;
using Google.GData.Extensions;
using Google.GData.YouTube;
using Google.GData.Extensions.MediaRss;
using Google.YouTube;
namespace YouTube_Manager
{
public partial class Form1 : Form
{
YouTubeRequestSettings settings;
YouTubeRequest request;
string username = "myusername", password = "mypass", devkey = "mydevkey";
string filename, filetype, filemime;
public string Devkey
{
get { return devkey; }
set { devkey = value; }
}
public string Password
{
get { return password; }
set { password = value; }
}
public string Username
{
get { return username; }
set { username = value; }
}
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
Devkey = devkey;
Password = password;
Username = username;
settings = new YouTubeRequestSettings("YouTube_Manager", devkey, username, password);
request = new YouTubeRequest(settings);
if (cmbCat.Items.Count > 0)
{
cmbCat.SelectedIndex = 0;
}
if (cmbPrivacy.Items.Count > 0)
{
cmbPrivacy.SelectedIndex = 0;
}
}
public void UploadVideo()
{
Video video = new Video();
video.Title = txtTitle.Text;
video.Tags.Add(new MediaCategory(cmbCat.SelectedItem.ToString(), YouTubeNameTable.CategorySchema));
video.Keywords = txtKeyWords.Text;
if (cmbPrivacy.SelectedIndex == 1)
video.Private = true;
else
video.Private = false;
GetFileMime();
video.MediaSource = new MediaFileSource(filename, filemime);
request.Upload(video);
MessageBox.Show("Successfully uploaded");
}
public void GetFileMime()
{
switch (filetype)
{
case "flv": filemime = "video/x-flv"; break;
case "avi": filemime = "video/avi"; break;
case "3gp": filemime = "video/3gpp"; break;
case "mov": filemime = "video/quicktime"; break;
default: filemime = "video/quicktime"; break;
}
}
private void btnChoosefile_Click(object sender, EventArgs e)
{
string tmp;
choosefile.ShowDialog();
tmp = choosefile.FileName;
txtFilepath.Text = tmp;
string[] title = tmp.Split('\\');
int i = title.GetUpperBound(0);
string temp = title[i];
string[] title1 = temp.Split('.');
txtTitle.Text = title1[0];
filename = tmp.Replace("\\", "\\\\");
filetype = title1[1];
}
private void button1_Click(object sender, EventArgs e)
{
DialogResult result = MessageBox.Show("By clicking 'upload,' " +
"you certify that you own all rights to the content or that you are authorized" +
"by the owner to make the content publicly available on YouTube, and that it otherwise" +
"complies with the YouTube Terms of Service located at http://www.youtube.com/t/terms", "Aggrement",
MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (result == DialogResult.Yes)
{
UploadVideo();
}
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
request.Upload(video);
Google.GData.Client.InvalidCredentialsException was unhandled
HResult=-2146233088
Message=Invalid credentials
Source=Google.GData.Client
StackTrace:
at Google.GData.Client.Utilities.QueryClientLoginToken(GDataCredentials gc, String serviceName, String applicationName, Boolean fUseKeepAlive, IWebProxy proxyServer, Uri clientLoginHandler)
at Google.GData.Client.GDataGAuthRequest.QueryAuthToken(GDataCredentials gc)
at Google.GData.Client.GDataGAuthRequest.EnsureCredentials()
at Google.GData.Client.GDataRequest.EnsureWebRequest()
at Google.GData.Client.GDataGAuthRequest.EnsureWebRequest()
at Google.GData.Client.GDataGAuthRequest.CopyRequestData()
at Google.GData.Client.GDataGAuthRequest.Execute(Int32 retryCounter)
at Google.GData.Client.GDataGAuthRequest.Execute()
at Google.GData.Client.MediaService.EntrySend(Uri feedUri, AtomBase baseEntry, GDataRequestType type, AsyncSendData data)
at Google.GData.Client.Service.Insert(Uri feedUri, AtomEntry newEntry, AsyncSendData data)
at Google.GData.Client.Service.Insert[TEntry](Uri feedUri, TEntry entry)
at Google.GData.YouTube.YouTubeService.Upload(String userName, YouTubeEntry entry)
at Google.YouTube.YouTubeRequest.Upload(String userName, Video v)
at Google.YouTube.YouTubeRequest.Upload(Video v)
at YouTube_Manager.Form1.UploadVideo() in d:\C-Sharp\YouTube_Manager\YouTube_Manager\YouTube_Manager\Form1.cs:line 81
at YouTube_Manager.Form1.button1_Click(Object sender, EventArgs e) in d:\C-Sharp\YouTube_Manager\YouTube_Manager\YouTube_Manager\Form1.cs:line 122
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at YouTube_Manager.Program.Main() in d:\C-Sharp\YouTube_Manager\YouTube_Manager\YouTube_Manager\Program.cs:line 18
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
最佳答案
ClientLogin (登录名和密码)已于 2012 年 4 月 20 日弃用,并于 2015 年 5 月 26 日关闭。此代码将不再有效,您需要切换到使用 Oauth2。
我还想建议您使用新的 Google 客户端库
Install-Package Google.Apis.YouTube.v3
关于c# - 为什么尝试将视频文件上传到 youtube 时出现 InvalidCredentialsException?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30835055/
这是我在 form1 中的代码: using System; using System.Collections.Generic; using System.ComponentModel; using
我有一个 MVC4 应用程序正在尝试使用 C# GData API ( https://developers.google.com/gdata/client-cs ) 访问 Google 文档。 当我
我是一名优秀的程序员,十分优秀!