Using the following code:
<%
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
%>
I get the following error:
Microsoft VBScript runtime error ‘800a01a8’
Object required
/romans/admin_youtube_detail.asp, line 31
Which is: Dim title : title = entry.SelectSingleNode(“a:title”).Text
Can anyone help please?
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>
Your variables all seem messed up:-
I suspect you actually intended:-
The key here is naming. Name your variables well and the bugs are easier to see.
However having said that the resulting Url “http://gdata.youtube.com/feeds/api/videos/d8nxjUlbKJA” returns a 404.
(BTW this all feels very familiar, have I dealt with this before somewhere on SO?)
Edit
The true problem with this particular feed is that the Content-Type header specifies the content to be: “application/atom+xml”. Unfortunately the old MSXML3 ServerXMLHTTP object doesn’t recognise this content type as XML and therefore doesn’t populate the ResponseXML object.
You have two options, first if you have control of the server or know that MSXML6 is installed you can do this use that. Change the ProgID in the CreateObject to “MSXML2.ServerXMLHTTP.6.0” (you can also delete the SelectionLanguage setting since XPATH is default in MSXML6).
The other option is to load the
ResponseStreaminto an instance of the DOM yourself:-Instead of:-
use:-