我需要一些帮助。我尝试使用youtube api上传视频。我在c#中使用windows表单。 这就是我的所作所为:
var service = new YouTubeService("kslmfkmlskf",this._sharedConfiguration.youtubeApiKey);
service.setUserCredentials(this._sharedConfiguration.youtubeUserName, this._sharedConfiguration.youtubeUserPassword);
var newEntry = new YouTubeEntry();
string title = "test";
string description = "test test test";
string keywords = "testa testb testc";
newEntry.Media = new Google.GData.YouTube.MediaGroup();
newEntry.Media.Categories.Add(new MediaCategory("Movies", YouTubeNameTable.CategorySchema));
newEntry.Media.Keywords = new MediaKeywords(keywords);
newEntry.Media.Description = new MediaDescription(description);
newEntry.Media.Title = new MediaTitle(title);
newEntry.MediaSource = new MediaFileSource("E:\\cine_buzz\\automate_trailer\\toupload\\demo.mov", "video/quicktime");
var createEntry = new YouTubeEntry();
createEntry = service.Upload(newEntry);
我有一个像这样的异常回复:
{Google.GData.Client.GDataRequestException: Execution of request failed: https://uploads.gdata.youtube.com/feeds/api/users/default/uploads ---> System.Net.WebException: Le serveur distant a retourné une erreur : (400) Demande incorrecte.
à System.Net.HttpWebRequest.GetResponse()
à Google.GData.Client.GDataRequest.Execute()
--- Fin de la trace de la pile d'exception interne ---
à Google.GData.Client.GDataRequest.Execute()
à Google.GData.Client.GDataGAuthRequest.Execute(Int32 retryCounter)
à Google.GData.Client.GDataGAuthRequest.Execute()
à Google.GData.Client.MediaService.EntrySend(Uri feedUri, AtomBase baseEntry, GDataRequestType type, AsyncSendData data)
à Google.GData.Client.Service.Insert(Uri feedUri, AtomEntry newEntry, AsyncSendData data)
à Google.GData.Client.Service.Insert[TEntry](Uri feedUri, TEntry entry)
à Google.GData.YouTube.YouTubeService.Upload(String userName, YouTubeEntry entry)
à Google.GData.YouTube.YouTubeService.Upload(YouTubeEntry entry)
à CineBuzzAutomateTrailer.frmUploadYoutube.upload() dans C:\Users\Yeurl\Documents\Visual Studio 2010\Projects\CineBuzzAutomateTrailer\CineBuzzAutomateTrailer\frmUploadYoutube.cs:ligne 105
à CineBuzzAutomateTrailer.frmUploadYoutube.btnTest_Click(Object sender, EventArgs e) dans C:\Users\Yeurl\Documents\Visual Studio 2010\Projects\CineBuzzAutomateTrailer\CineBuzzAutomateTrailer\frmUploadYoutube.cs:ligne 113
à System.Windows.Forms.Control.OnClick(EventArgs e)
à System.Windows.Forms.Button.OnClick(EventArgs e)
à System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
à System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
à System.Windows.Forms.Control.WndProc(Message& m)
à System.Windows.Forms.ButtonBase.WndProc(Message& m)
à System.Windows.Forms.Button.WndProc(Message& m)
à System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
à System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
à System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
à System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
à System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
à System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
à System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
à System.Windows.Forms.Application.Run(Form mainForm)
à CineBuzzAutomateTrailer.Program.Main() dans C:\Users\Yeurl\Documents\Visual Studio 2010\Projects\CineBuzzAutomateTrailer\CineBuzzAutomateTrailer\Program.cs:ligne 18
à System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
à System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
à Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
à System.Threading.ThreadHelper.ThreadStart_Context(Object state)
à System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
à System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
à System.Threading.ThreadHelper.ThreadStart()}
和这个
<errors xmlns="http://schemas.google.com/g/2005">
- <error>
<domain>GData</domain>
<code>InvalidEntryException</code>
<internalReason>Validation failed</internalReason>
</error>
</errors>
我不明白我做了什么是错的。 Thanx寻求帮助
答案 0 :(得分:2)
我认为您的API访问权限未配置API控制台。
我建议您使用V3而不是GData。有一个Java示例与C#和这一个非常相似。
您还应该在此处从API控制台设置API访问权限,然后从那里打开Youtube Data v3 API。 “https://code.google.com/apis/console”
答案 1 :(得分:0)
试试这段代码,这样可行。
Video newVideo = new Video();
newVideo.Title ="My Test Movie";
newVideo.Tags.Add(new MediaCategory("Autos", YouTubeNameTable.CategorySchema));
newVideo.Keywords = "cars, funny";
newVideo.Description = "My description";
newVideo.YouTubeEntry.Private = false;
newVideo.Tags.Add(new MediaCategory("mydevtag, anotherdevtag",
YouTubeNameTable.DeveloperTagSchema));
newVideo.YouTubeEntry.Location = new GeoRssWhere(37, -122);
// alternatively, you could just specify a descriptive string
// newVideo.YouTubeEntry.setYouTubeExtension("location", "Mountain View, CA");
newVideo.YouTubeEntry.MediaSource = new MediaFileSource("c:\\file.mov",
"video/quicktime");
Video createdVideo = request.Upload(newVideo);
参考:https://developers.google.com/youtube/2.0/developers_guide_dotnet?csw=1#Direct_Upload