views:

684

answers:

2

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'&gt;
  <id>http://gdata.youtube.com/feeds/api/videos/d8nxjUlbKJA&lt;/id&gt;
  <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'/&gt;
  <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&amp;amp;feature=youtube_gdata'/&gt;
  <link rel='http://gdata.youtube.com/schemas/2007#video.responses' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/videos/d8nxjUlbKJA/responses'/&gt;
  <link rel='http://gdata.youtube.com/schemas/2007#video.related' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/videos/d8nxjUlbKJA/related'/&gt;
  <link rel='http://gdata.youtube.com/schemas/2007#mobile' type='text/html' href='http://m.youtube.com/details?v=d8nxjUlbKJA'/&gt;
  <link rel='self' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/videos/d8nxjUlbKJA'/&gt;
  <author>
    <name>gelattinatv</name>
    <uri>http://gdata.youtube.com/feeds/api/users/gelattinatv&lt;/uri&gt;
  </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'&gt;Education&lt;/media:category&gt;
    <media:content url='http://www.youtube.com/v/d8nxjUlbKJA?f=videos&amp;amp;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&amp;amp;feature=youtube_gdata'/&gt;
    <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>
+1  A: 

Your variables all seem messed up:-

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

I suspect you actually intended:-

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

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 ResponseStream into an instance of the DOM yourself:-

Instead of:-

Dim xml : Set xml = xhr.ResponseXML

use:-

Dim xml : Set xml = CreateObject("MSXML2.DOMDocument.3.0")
xml.Load xhr.ResponseStream
AnthonyWJones
Yes you have, but i'm new to SO and couldn't see where I could PM you or add a reply to the question. I have changed the code to the one you suggested, but still get:Microsoft VBScript runtime error '800a01a8'Object requiredadmin_youtube_detail.asp, line 29which is: Dim title : title = entry.SelectSingleNode("a:title").Text
Lyno
It would help if I could see the feed myself but I just get a 404. However if your code is getting a 404 you wouldn't be reaching the line that is erroring. So either I've the url wrong or your code still isn't what I think it is.
AnthonyWJones
Posted the XML feed i recieve, above.
Lyno
Edited my answer with solution
AnthonyWJones
Thanks Anthony, that did th job! Once I'd changed it to MSXML2.ServerXMLHTTP.6.0, it worked like a dream! One other question: How do I access things like media:thumbnail data since there's multiple entries? Thanks again.
Lyno
Use .SelectNodes("media:group/media:thumbnail") which will return a List of XmlNodes that you can enumerate with `For Each`. Remember to add the media alias to the ns variable.
AnthonyWJones
A: 

I tryied to use MSXML2.ServerXMLHTTP.3.0 on my server. I had too much problems, now I'm using Microsoft.XMLHTTP everything works fine.

No more errors.

Simon