0

我需要帮助。我尝试使用 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>

我不明白我所做的有什么问题。感谢帮助

4

2 回答 2

2

我认为您的 API 访问权限未配置 API 控制台。

我建议您使用 V3 而不是 GData。有一个与 C# 和这个非常相似的 Java 示例。

" https://code.google.com/p/youtube-api-samples/source/browse/samples/java/youtube-cmdline-uploadvideo-sample/src/main/java/com/google/api/services/samples /youtube/cmdline/youtube_cmdline_uploadvideo_sample/UploadVideo.java "

您还应该在此处从 API 控制台设置您的 API 访问权限,并从那里打开 Youtube Data v3 API。“ https://code.google.com/apis/console

于 2013-03-03T01:05:59.310 回答
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

于 2015-07-01T07:47:19.343 回答