经典 ASP MSXML2.ServerHTTP Post - Youtube Api

发布于 2024-09-12 14:55:44 字数 2589 浏览 3 评论 0原文

我正在尝试构建一个可以将文件上传到 youtube 的应用程序。 我已经让 OAuth 正常工作,并且 Youtube 正在返回一个会话!

我遇到的问题是,youtube 要求我进行 XMLHTTP POST 来获取可以通过我的网页上传的网址。

我不知道如何使用 youtube 所需的额外参数制作 XMLHTTP Post。 他们有 PHP 和 .net 的代码示例,我还不明白:(

这就是我陷入困境的地方: http://code.google.com/apis/youtube/2.0/ Developers_guide_protocol_browser_based_uploading.html#Sending_a_Browser_Upload_API_Request

我不知道如何格式化 xml http 命令来拥有 youtube 想要的所有变量。 请帮助...

这就是他们想要的..

 POST /action/GetUploadToken HTTP/1.1
Host: gdata.youtube.com
Authorization: AuthSub token="DXAA...sdb8"
GData-Version: 2
X-GData-Key: key=adf15ee97731bca89da876c...a8dc
Content-Length: 1941255
Content-Type: application/atom+xml; charset=UTF-8

<?xml version="1.0"?>
<entry xmlns="http://www.w3.org/2005/Atom"
  xmlns:media="http://search.yahoo.com/mrss/"
  xmlns:yt="http://gdata.youtube.com/schemas/2007">
  <media:group>
    <media:title type="plain">Bad Wedding Toast</media:title>
    <media:description type="plain">
      I gave a bad toast at my friend's wedding.
    </media:description>
    <media:category
      scheme="http://gdata.youtube.com/schemas/2007/categories.cat">People
    </media:category>
    <media:keywords>toast, wedding</media:keywords>
  </media:group>
</entry>

这是我现在拥有的代码: 我想我需要标题? 当我发布它时,我收到未授权的回复。 我还尝试创建一个旧的 html 并尝试,但它不起作用...

不知道这些参数是如何发送的:

这是我得到的

Set  xmlHttp = CreateObject("MSXML2.ServerXMLHTTP")

URLString = "http://gdata.youtube.com/action/GetUploadToken"
SendString = ""
    SendString = SendString & "Authorization: AuthSub token=" &  token
xmlHttp.open "POST", URLString & "?" & SendString
xmlHttp.setRequestHeader "Host:", "gdata.youtube.com"
xmlHttp.setRequestHeader "Authorization: AuthSub token=", token
xmlHttp.setRequestHeader "GData-Version:", "2"
xmlHttp.setRequestHeader "Content-Length:", "<content_length>"
xmlHttp.setRequestHeader "Content-Type", "application/atom+xml; charset=UTF-"
xmlHttp.send SendString

If xmlHttp.Status >= 400 And xmlHttp.Status <= 599 Then
    Response.Write "<BR><BR><BR>Error Occured: " & xmlHttp.statusText
Else
  '  ReturnData = Replace(xmlHttp.responseText, "&", ",")
        Response.Write "<BR><BR><BR>WENT GOOD?<BR>" & xmlHttp.responseText
End If

I am trying to build an application where i can upload files to youtube.
I have gotten OAuth working, and Youtube is returning a session!

The problem i am having is, youtube requires i make an XMLHTTP POST to get a url where i can upload through my web page.

I have no idea how to make an XMLHTTP Post with the extra parameters youtube requires.
They have code samples in PHP and .net both of which i dont understand yet :(

This is where i am stuck:
http://code.google.com/apis/youtube/2.0/developers_guide_protocol_browser_based_uploading.html#Sending_a_Browser_Upload_API_Request

I dont know how to Format an xml http command to have all those variables youtube wants.
Please help...

here is what they want..

 POST /action/GetUploadToken HTTP/1.1
Host: gdata.youtube.com
Authorization: AuthSub token="DXAA...sdb8"
GData-Version: 2
X-GData-Key: key=adf15ee97731bca89da876c...a8dc
Content-Length: 1941255
Content-Type: application/atom+xml; charset=UTF-8

<?xml version="1.0"?>
<entry xmlns="http://www.w3.org/2005/Atom"
  xmlns:media="http://search.yahoo.com/mrss/"
  xmlns:yt="http://gdata.youtube.com/schemas/2007">
  <media:group>
    <media:title type="plain">Bad Wedding Toast</media:title>
    <media:description type="plain">
      I gave a bad toast at my friend's wedding.
    </media:description>
    <media:category
      scheme="http://gdata.youtube.com/schemas/2007/categories.cat">People
    </media:category>
    <media:keywords>toast, wedding</media:keywords>
  </media:group>
</entry>

Here is the code i have now:
I think i need the Headers?
When i post it i get a response of not authorized.
I also tried to create an old html and try that but it does not work...

Have no idea how those paramenters are sent:

Here is what i got

Set  xmlHttp = CreateObject("MSXML2.ServerXMLHTTP")

URLString = "http://gdata.youtube.com/action/GetUploadToken"
SendString = ""
    SendString = SendString & "Authorization: AuthSub token=" &  token
xmlHttp.open "POST", URLString & "?" & SendString
xmlHttp.setRequestHeader "Host:", "gdata.youtube.com"
xmlHttp.setRequestHeader "Authorization: AuthSub token=", token
xmlHttp.setRequestHeader "GData-Version:", "2"
xmlHttp.setRequestHeader "Content-Length:", "<content_length>"
xmlHttp.setRequestHeader "Content-Type", "application/atom+xml; charset=UTF-"
xmlHttp.send SendString

If xmlHttp.Status >= 400 And xmlHttp.Status <= 599 Then
    Response.Write "<BR><BR><BR>Error Occured: " & xmlHttp.statusText
Else
  '  ReturnData = Replace(xmlHttp.responseText, "&", ",")
        Response.Write "<BR><BR><BR>WENT GOOD?<BR>" & xmlHttp.responseText
End If

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

凉世弥音 2024-09-19 14:55:44

首先, setRequestHeader 不带冒号。它应该只是

xmlHttp.setRequestHeader "Host", "gdata.youtube.com"
xmlHttp.setRequestHeader "Authorization", "AuthSub token=" & token
xmlHttp.setRequestHeader "GData-Version", "2"
xmlHttp.setRequestHeader "Content-Length", "<content_length>" <-- THIS IS IMPORTANT!
xmlHttp.setRequestHeader "Content-Type", "application/atom+xml; charset=UTF-8"

“下一步”,您发送的内容长度正确吗?这需要准确。
我认为您的 Content-Type 标头末尾缺少的“8”是一个拼写错误。

最后,您需要立即安装 Fiddler ,让您的生活更简单。

First, setRequestHeader doesn't take a colon. It should just be

xmlHttp.setRequestHeader "Host", "gdata.youtube.com"
xmlHttp.setRequestHeader "Authorization", "AuthSub token=" & token
xmlHttp.setRequestHeader "GData-Version", "2"
xmlHttp.setRequestHeader "Content-Length", "<content_length>" <-- THIS IS IMPORTANT!
xmlHttp.setRequestHeader "Content-Type", "application/atom+xml; charset=UTF-8"

Next, are you sending the correct content-length? This NEEDS to be accurate.
I assume the missing "8" from your Content-Type header at the end was a typo.

Finally, you NEED to install Fiddler right away and make your life simpler.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文