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>
According to the response, your media:category
might be incorrect. Try:
video.Tags.Add(new MediaCategory("Sports", YouTubeNameTable.CategorySchema));
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With