Google API - sporadic success

B

botch

Hi! I'm trying to get some help implementing a classic ASP version of
the Google API search (http://www.google.com/apis/). I've got a version
that works, but it's very sporadic. Sometimes it works, sometimes it
comes back blank, sometimes it gives an error. No other ASP version of
this API has any problems.

Dim Google_Web_APIs_license_key, Search_String
Google_Web_APIs_license_key = "HIDDEN"
Search_String = Request("q")
If Search_String = "" Then
Search_String = "transformers"
End If
'
' The SOAP message (doGoogleSearch.xml) was downloaded from the Google
API soap-examples.
' Dump the SOAP message into an XML document and set the key value,
search string value and start index.
'
Set objInputXMLDoc = Server.CreateObject("Microsoft.XMLDOM")
objInputXMLDoc.load Server.MapPath("doGoogleSearch.xml")
objInputXMLDoc.selectSingleNode("//key").Text =
Google_Web_APIs_license_key
objInputXMLDoc.selectSingleNode("//q").Text = Search_String
objInputXMLDoc.selectSingleNode("//start").Text = 0
'
' Post the SOAP message.
'
Set objXMLHTTP = Server.CreateObject("Microsoft.XMLHTTP")
objXMLHTTP.open "post", "http://api.google.com/search/beta2", False
objXMLHTTP.setRequestHeader "Content-Type", "text/xml"
objXMLHTTP.setRequestHeader "SOAPAction", "doGoogleSearch"
objXMLHTTP.send objInputXMLDoc
showXML(objXMLHTTP.responseText)
'
' Dump the results into an XML document.
'
Set objOutputXMLDoc = Server.CreateObject("Microsoft.XMLDOM")
objOutputXMLDoc.loadXML objXMLHTTP.responseText
'
' Parse the XML document.
'
Set Nodes = objOutputXMLDoc.selectNodes("//item")
For Each Node In Nodes
Response.Write "<a href=""" & Node.selectSingleNode("URL").Text & """>"
& Node.selectSingleNode("title").Text & "</a>
" & VbCrLf
'Response.Write Node.selectSingleNode("snippet").Text & "

" & VbCrLf
Next

Function showXML(XMLSource)
Response.Clear
Response.Write XMLSource
Response.End
End Function

The page is at http://www.botchthecrab.com/searchNew2.asp
By default it searches for "transformers", but you can change the
search parameter like so:
http://www.botchthecrab.com/searchNew2.asp?q=football

You have to reload a few times to get all the desired results, but I
guarantee it works sometimes and sometimes not.

Any help would be appreciated!

~ Botch
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,044
Latest member
RonaldNen

Latest Threads

Top