使用以下代码:
<%
Option Explicit
Response.Buffer = True
Dim videoVimeo : videoVimeo = "http://vimeo.com/5866977"
Dim videoYoutube : videoYoutube = "http://www.youtube.com/watch?v=d8nxjUlbKJA"
videoYoutube = Replace(videoYoutube,"http://www.youtube.com/watch?v=","")
videoYoutube = "http://gdata.youtube.com/feeds/api/videos/" & videoYoutube
Dim xhr: Set xhr= Server.CreateObject("MSXML2.ServerXMLHTTP.3.0")
xhr.Open "GET", videoYoutube, False
xhr.Send
If xhr.Status = 200 Then
Dim xml : Set xml = xhr.ResponseXML
xml.SetProperty "SelectionLanguage", "XPath"
Dim ns : ns = "xmlns:a='http://www.w3.org/2005/Atom' "
ns = ns & "xmlns:gd='http://schemas.google.com/g/2005' "
xml.SetProperty "SelectionNamespaces", ns
Dim entry : Set entry = xml.DocumentElement
Dim title : title = entry.SelectSingleNode("a:title").Text
Dim published : published = entry.SelectSingleNode("a:published")
Dim rating : rating = entry.SelectSingleNode("gd:rating").GetAttribute("average")
End If
%>
我收到以下错误:
Microsoft VBScript运行时错误'800a01a8'
需要对象
/romans/admin_youtube_detail.asp,第31行
其中:Dim title:title = entry.SelectSingleNode(“a:title”)。Text
有人可以帮忙吗?
XML Feed:
<?xml version='1.0' encoding='UTF-8'?>
<entry xmlns='http://www.w3.org/2005/Atom' xmlns:media='http://search.yahoo.com/mrss/' xmlns:gd='http://schemas.google.com/g/2005' xmlns:yt='http://gdata.youtube.com/schemas/2007'>
<id>http://gdata.youtube.com/feeds/api/videos/d8nxjUlbKJA</id>
<published>2009-08-01T00:07:02.000Z</published>
<updated>2009-08-31T22:21:46.000Z</updated>
<category scheme='http://schemas.google.com/g/2005#kind' term='http://gdata.youtube.com/schemas/2007#video'/>
<category scheme='http://gdata.youtube.com/schemas/2007/categories.cat' term='Education' label='Education'/>
<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='ToditoFree'/>
<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='freebies'/>
<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='gelattina'/>
<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='gelattinatv'/>
<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='free'/>
<category scheme='http://gdata.youtube.com/schemas/2007/keywords.cat' term='stuff'/>
<title type='text'>ToditoFree: Gratis!!</title>
<content type='text'/>
<link rel='alternate' type='text/html' href='http://www.youtube.com/watch?v=d8nxjUlbKJA&feature=youtube_gdata'/>
<link rel='http://gdata.youtube.com/schemas/2007#video.responses' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/videos/d8nxjUlbKJA/responses'/>
<link rel='http://gdata.youtube.com/schemas/2007#video.related' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/videos/d8nxjUlbKJA/related'/>
<link rel='http://gdata.youtube.com/schemas/2007#mobile' type='text/html' href='http://m.youtube.com/details?v=d8nxjUlbKJA'/>
<link rel='self' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/videos/d8nxjUlbKJA'/>
<author>
<name>gelattinatv</name>
<uri>http://gdata.youtube.com/feeds/api/users/gelattinatv</uri>
</author>
<gd:comments>
<gd:feedLink href='http://gdata.youtube.com/feeds/api/videos/d8nxjUlbKJA/comments' countHint='0'/>
</gd:comments>
<media:group>
<media:category label='Education' scheme='http://gdata.youtube.com/schemas/2007/categories.cat'>Education</media:category>
<media:content url='http://www.youtube.com/v/d8nxjUlbKJA?f=videos&app=youtube_gdata' type='application/x-shockwave-flash' medium='video' isDefault='true' expression='full' duration='45' yt:format='5'/>
<media:content url='rtsp://rtsp2.youtube.com/CiILENy73wIaGQmQKFtJjfHJdxMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp' type='video/3gpp' medium='video' expression='full' duration='45' yt:format='1'/>
<media:content url='rtsp://rtsp2.youtube.com/CiILENy73wIaGQmQKFtJjfHJdxMYESARFEgGUgZ2aWRlb3MM/0/0/0/video.3gp' type='video/3gpp' medium='video' expression='full' duration='45' yt:format='6'/>
<media:description type='plain'/>
<media:keywords>ToditoFree, freebies, gelattina, gelattinatv, free, stuff</media:keywords>
<media:player url='http://www.youtube.com/watch?v=d8nxjUlbKJA&feature=youtube_gdata'/>
<media:thumbnail url='http://i.ytimg.com/vi/d8nxjUlbKJA/2.jpg' height='90' width='120' time='00:00:22.500'/>
<media:thumbnail url='http://i.ytimg.com/vi/d8nxjUlbKJA/1.jpg' height='90' width='120' time='00:00:11.250'/>
<media:thumbnail url='http://i.ytimg.com/vi/d8nxjUlbKJA/3.jpg' height='90' width='120' time='00:00:33.750'/>
<media:thumbnail url='http://i.ytimg.com/vi/d8nxjUlbKJA/0.jpg' height='240' width='320' time='00:00:22.500'/>
<media:title type='plain'>ToditoFree: Gratis!!</media:title>
<yt:duration seconds='45'/>
</media:group>
<yt:statistics favoriteCount='0' viewCount='46'/>
</entry>
答案 0 :(得分:1)
你的变量似乎搞得一团糟: -
Dim videoYoutube : videoYoutube = "http://www.youtube.com/watch?v=d8nxjUlbKJA"
videoYoutube = Replace(videoYoutube,"http://www.youtube.com/watch?v=","")
videoYoutube = "http://gdata.youtube.com/feeds/api/videos/" & videoYoutube
Dim xhr: Set xhr= Server.CreateObject("MSXML2.ServerXMLHTTP.3.0")
xhr.Open "GET", videoYoutube, False
我怀疑你确实打算: -
Dim originalUrl: originalUrl= "http://www.youtube.com/watch?v=d8nxjUlbKJA"
Dim feedUrl : feedUrl = Replace(originalUrl, "http://www.youtube.com/watch?v=", "")
feedUrl = "http://gdata.youtube.com/feeds/api/videos/" & feedUrl
Dim xhr: Set xhr= Server.CreateObject("MSXML2.ServerXMLHTTP.3.0")
xhr.Open "GET", feedUrl, False
此处的关键是命名。为变量命名,并且更容易看到错误。 但是,如果说生成的Url“http://gdata.youtube.com/feeds/api/videos/d8nxjUlbKJA”返回404。
(顺便说一下,这一切都非常熟悉,我在SO之前的某个地方处理过这个吗?)
修改强>
此特定Feed的真正问题是Content-Type标头指定内容为:“application / atom + xml”。遗憾的是,旧的MSXML3 ServerXMLHTTP对象无法将此内容类型识别为XML,因此不会填充ResponseXML对象。
您有两个选择,首先,如果您拥有对服务器的控制权或者知道安装了MSXML6,您可以使用它。将CreateObject中的ProgID更改为“MSXML2.ServerXMLHTTP.6.0”(您也可以删除SelectionLanguage设置,因为XPATH是MSXML6中的默认设置)。
另一种选择是自己将ResponseStream
加载到DOM的实例中: -
而不是: -
Dim xml : Set xml = xhr.ResponseXML
使用: -
Dim xml : Set xml = CreateObject("MSXML2.DOMDocument.3.0")
xml.Load xhr.ResponseStream
答案 1 :(得分:0)
我尝试在我的服务器上使用MSXML2.ServerXMLHTTP.3.0
我有太多问题,所以,现在我正在使用Microsoft.XMLHTTP
,一切正常。
不再有错误。