YouTube API v2 Classic ASP Browser Based Uploading GetUploadToken not working

jeus16

New Member
This is a case of using classic asp (VBScript) and would like to connect to the YouTube API v2 to upload videos to an account. I've been able to get to the point where we want to get the Upload Token but am having a hard time getting a successful response.Here is what I have so far:\[code\] Set xmlHttp = CreateObject("MSXML2.ServerXMLHTTP")URLString = "https://accounts.google.com/o/oauth2/token"SendString = ""SendString = SendString & "<?xml version=""1.0""?>"SendString = SendString & "<entry xmlns=""http://www.w3.org/2005/Atom"" "SendString = SendString & "xmlns:media=""http://search.yahoo.com/mrss/"" "SendString = SendString & "xmlns:yt=""http://gdata.youtube.com/schemas/2007"">"SendString = SendString & "<media:group>"SendString = SendString & "<media:title type=""plain"">Bad Wedding Toast</media:title>"SendString = SendString & "<media:description type=""plain"">"SendString = SendString & "I gave a bad toast at my friend's wedding."SendString = SendString & "</media:description>"SendString = SendString & "<media:category scheme=""http://gdata.youtube.com/schemas/2007/categories.cat"">People</media:category>"SendString = SendString & "<media:keywords>toast, wedding</media:keywords>"SendString = SendString & "</media:group>"SendString = SendString & "</entry>"' SendString = "Authorization: AuthSub token=" & accessTokenCall xmlHttp.open("POST", URLString, False)Call xmlHttp.setRequestHeader("POST", "/action/GetUploadToken HTTP/1.1")Call xmlHttp.setRequestHeader("Host", "gdata.youtube.com")Call xmlHttp.setRequestHeader("Authorization", "AuthSub token=" & accessToken)Call xmlHttp.setRequestHeader("GData-Version", "2")Call xmlHttp.setRequestHeader("X-GData-Key", "key=" & YOUTUBE_DEV_KEY)Call xmlHttp.setRequestHeader("Content-Length", 1941255)Call xmlHttp.setRequestHeader("Content-Type", "application/atom+xml; charset=UTF-8")Call xmlHttp.Send(SendString)\[/code\]The error returned:\[code\]{ "error" : "invalid_request" } \[/code\]What am I missing? Or doing incorrectly? One thing that I'm probably quite wrong about is, how do I calculate the content-length? I haven't seen a built-in function in VBScript and googling it has been non-productive for me so far. There were suggestions that said to just leave out the content-length or set it to -1, but both attempts resulted in the same error. I'm not sure if the content-length is the source of the error either.Thanks in advance for any help!UPDATE: I figured it out. Woot!To answer one of my questions, the content-length need not be set, nor specified. The docs that say the content-length is not required were correct.Couple of corrections to code above:\[code\]URLString = "http://gdata.youtube.com/action/GetUploadToken"...Call objXmlHttp.setRequestHeader("Authorization", "Bearer " & accessToken)\[/code\]Also, delete the Content-Length line.Hope this helps anyone else that might be having trouble!
 
Top