IIS ASP - Google API - sporadic success

This is Interesting: Free IT Magazines  
Home > Archive > IIS ASP > March 2006 > Google API - sporadic success





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Google API - sporadic success
botch@botchthecrab.com

2006-03-16, 5:52 pm

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

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com