400错误请求使用C#YouTube API将视频上传到YouTube时出错

pat*_*719 4 c# youtube asp.net youtube-api youtube.net-api

我似乎无法将我的ASP.net应用程序成功发布到我的YouTube帐户,但无论我做什么,我都会收到400 Bad Request错误.我使用YouTube文档创建代码并获取开发密钥.此外,我没有收到和身份验证错误,所以我相信我的参数是正确的.尽管进行了大量的搜索,我仍然无法找到我的任务的确切答案,所以我只能假设我错误地使用了API或省略了一些关键的东西.

我的使用指令如下

using System; using Google.GData.Client; using Google.GData.YouTube; using Google.GData.Extensions; using Google.GData.Extensions.MediaRss; using Google.YouTube;

我的调用API的代码就在这里

YouTubeRequestSettings settings = new YouTubeRequestSettings("k2ps",
  YOU_TUBE_DEVELOPER_KEY, YOU_TUBE_USER_NAME, YOU_TUBE_PASSWORD);
  YouTubeRequest request = new YouTubeRequest(settings);

  Video video = new Video();
  video.Title = title;
  video.Tags.Add(new MediaCategory(sport, YouTubeNameTable.CategorySchema));
  video.Keywords = keyword;
  video.Description = "K2ps";  //todo replace this with the preview text
  video.YouTubeEntry.Private = false;

  video.YouTubeEntry.MediaSource = new MediaFileSource(videoPath, "video/x-flv");
  Video createdVideo = request.Upload(video);
Run Code Online (Sandbox Code Playgroud)

我正在抛出HTTP 400 Bad请求异常.我用fiddler来获得下面的原始响应.

执行请求失败: Google.GData.Client上的http://uploads.gdata.youtube.com/feeds/api/users/default/uploads

   HTTP/1.1 400 Bad Request
    Server: Upload Server Built on Jun 6 2011 12:48:11 (1307389691)
    X-GData-User-Country: US
    Content-Type: text/xml; charset=UTF-8
    Date: Thu, 09 Jun 2011 02:07:30 GMT
    Pragma: no-cache
    Expires: Fri, 01 Jan 1990 00:00:00 GMT
    Cache-Control: no-cache, no-store, must-revalidate
    Content-Length: 257



        <?xml version='1.0' encoding='UTF-8'?>
           <errors>
              <error>
                <domain>yt:validation</domain>
                <code>invalid_value</code>
         <location type='xpath'>
 media:group/media:category[@scheme='http://gdata.youtube.com/schemas/2007/categories.cat']/text()</location>
              </error>
          </errors>
Run Code Online (Sandbox Code Playgroud)

key*_*rdP 5

根据回复,你media:category可能不正确.尝试:

video.Tags.Add(new MediaCategory("Sports", YouTubeNameTable.CategorySchema));
Run Code Online (Sandbox Code Playgroud)