Google API - sporadic success

Discussion in 'ASP General' started by botch@botchthecrab.com, Mar 16, 2006.

  1. Guest

    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
    , Mar 16, 2006
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?VHJhdmlz?=

    Sporadic ASP.NET State Server Errors

    =?Utf-8?B?VHJhdmlz?=, Jan 20, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    472
    Alvin Bruney
    Jan 24, 2004
  2. =?Utf-8?B?VmljdG9yIEFsY2F6YXI=?=

    Sporadic "Unable to validate data" and "Invalid length for a Base-

    =?Utf-8?B?VmljdG9yIEFsY2F6YXI=?=, Jan 14, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    390
    =?Utf-8?B?VmljdG9yIEFsY2F6YXI=?=
    Jan 14, 2005
  3. Guillaume
    Replies:
    1
    Views:
    557
    =?ISO-8859-1?Q?Dav=E9mon?=
    Nov 16, 2005
  4. Ethan Herdrick
    Replies:
    1
    Views:
    93
    Ethan Herdrick
    May 11, 2006
  5. Replies:
    0
    Views:
    471
Loading...

Share This Page