4

I can't seem to get my ASP.net application to succesfully publish to my YouTube account but not matter what I do I get a 400 Bad Request error . I used the YouTube documentation to create my code and obtaining a dev key. Also, I am not receiving and authentication error so I believe that my parameters are correct. Despite a good deal of searching I cannot not find a definitive answer to my quests so I can only assume that I am using the API incorrectly or omitting something critical.

My using directive are as follows

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

My Code for calling the APIs is here

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);

I am getting a HTTP 400 Bad request exception being thrown. I used fiddler to get the raw response which is below.

Execution of request failed: http://uploads.gdata.youtube.com/feeds/api/users/default/uploads at 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>
pat8719
  • 1,700
  • 1
  • 26
  • 47

2 Answers2

5

According to the response, your media:category might be incorrect. Try:

video.Tags.Add(new MediaCategory("Sports", YouTubeNameTable.CategorySchema));
keyboardP
  • 68,824
  • 13
  • 156
  • 205
  • This answer is more helpful than mine. +1 – Brian Dishaw Jun 09 '11 at 02:44
  • the sport is a string parameter so unless I am mistaken the code I presented is effectively the same code you suggested. – pat8719 Jun 09 '11 at 02:46
  • @pat8719 - Does your `sport` string contain the word `Sports`? I believe "Sports" is the actual term YouTube has in their schema and as Brian mentioned, you need to specify one default category. – keyboardP Jun 09 '11 at 02:49
  • So what I totally misunderstood was that the Categories were a specific set of categories defined by YouTube not a category that I supplied. Changing it to 'Sports' worked perfectly. – pat8719 Jun 09 '11 at 02:56
  • @pat8719 - I believe if you want to add custom tags, you do the same thing but use `YouTubeNameTable.KeywordSchema` instead. (Haven't tested it, but worth a try). – keyboardP Jun 09 '11 at 02:57
3

You need to specify 1 default category from the 'http://gdata.youtube.com/schemas/2007/categories.cat' that they show in that error message.

It has to match the tags exactly that are specified in that document.

Muhammad Akhtar
  • 51,913
  • 37
  • 138
  • 191
Brian Dishaw
  • 5,767
  • 34
  • 49