Attempting to upload a video to YouTube using the .Net Api and browser based upload method was giving me a slight headache in the form of an unexplainable 400 Bad Request error.
While doing some concept testing for the DnnTube project I decided to takle the task of uploading a video directly to YouTube using the browser based upload method described here.
I fired up visual studio, opened the sample code provided in the Google .NET SDK and was on my way. I followed the example with a few changes based on what i was attempting to do and what I thought was needed (the documentation isnt exactly the greatest).
Started testing the initial page to enter the information about the video i was about to upload, click submit and boom 400 error. The exception had no information about what went wrong, just simply that it was a "400 Bad Request" which could mean about a billion different issues.
The error was the result of the following line of code which came straight from the example provided on the api documentation site:
Dim token As FormUploadToken = svc.FormUpload(entry)
I was completely baffled since i was following the example fairly close and remained baffled for about an hour. Then I noticed something missing.
Dim category As New MediaCategory("Autos")
category.Attributes("scheme") = YouTubeService.DefaultCategory
entry.Media.Categories.Add(category)After assigning a category to the video the upload started behaving better. Im still having a few issues with getting a 400 Bad Request, but I have at least tracked them down to certain properties of the video object being empty.
Would have saved a lot of time if a decent error message would have been returned rather that just saying "Somethings broken" :P