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

本文关键字:YouTube 出错 视频 请求 错误 API C#YouTube | 更新日期: 2023-09-27 17:58:39

我似乎无法让我的ASP.net应用程序成功发布到我的YouTube帐户,但无论我做什么,我都会收到400错误请求错误。我使用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);

我收到一个HTTP400错误请求异常。我用小提琴获取下面的原始响应。

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

   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>

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

根据响应,您的media:category可能不正确。尝试:

video.Tags.Add(new MediaCategory("Sports", YouTubeNameTable.CategorySchema));

您需要从错误消息中显示的'http://gdata.youtube.com/schemas/2007/categories.cat'中指定一个默认类别。

它必须与该文档中指定的标记完全匹配。