MSN Search API implemented in ASP only

Hello!

I've been working hard for a couple of days to implement the search API's of Google, Yahoo, and MSN in ASP only. I'm happy to say I've got it all working and I'm very, very happy with the results. MSN Search was perhaps the trickiest one to get working, but actually very reliable and easy once I understood the format of the SOAP envelope:

< xml version='1.0' encoding='UTF-8' >
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" xmlns:xsd="http://www.w3.org/1999/XMLSchema">
<SOAP-ENV:Body>
<ns1:Search xmlns:ns1="http://schemas.microsoft.com/MSNSearch/2005/09/fex">
<Request>
<AppID xsi:type="xsd:string">AppID Goes Here</AppID>
<Query xsi:type="xsd:string">Example Query</Query>
<CultureInfo xsi:type="xsd:string">en-GB</CultureInfo>
<SafeSearch xsi:type="xsd:string">Off</SafeSearch>
<Requests>
<SourceRequest>
<Source xsi:type="xsd:string">Web</Source>
<Offset xsi:type="xsd:int">0</Offset>
<Count xsi:type="xsd:int">50</Count>
<ResultFields xsi:type="xsd:string">All</ResultFields>
</SourceRequest>
</Requests>
</Request>
</ns1:Search>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

My question related to the CultureInfo. Using "en-GB", I can retrieve results similar to doing a normal browser based search at msn.co.uk, which is exactly what I want.

However, what I am ultimately trying to achieve is 2 sets of results:

  1. UK results of pages from the UK only:
    Same as doing a normal search at www.msn.co.uk and selecting the tick box "Only from the United Kingdom"
  2. UK results, from the web:
    Same as doinga normal search at www.msn.co.uk without putting a tick in the UK only box.

Does that make sense

I can achieve this happily with the other API's (Google, and Yahoo).
So I'm assuming I can do with with MSN by selecting the right CultureInfo

Hope there's an answer - thanks for any input!

BSolveIT




Answer this question

MSN Search API implemented in ASP only

  • E.Geg

    No problem at all.

    Slightly off topic, but I have a Google API function and soap packet for ASP also if it would be helpful Also have the Yahoo API solution for ASP, which uses REST as opposed to SOAP, but the ASP is very similar.

    I've also implemented them in ASP.Net 2.0 - which to be honest is much better. Let me know if you want me to post my source code

    Regards

    Mark.



  • Pat 34847

    Very interesting post bsolveit

    Thank you

  • Umberto Gatti

    I've seen some PHP code shared for this, does anyone care to share their ASP code I hate to re-create the wheel.

    Thanks!

    Brian


  • orac123456789

    Staggering! 4 Months later - and not a single follow up post from anyone Not even a MS

    Good forum, eh hehe um... yeah...ok.



  • Olivier Robin

    Hi James,

    Many, many thanks - this is exactly what I needed to know. Better late than never, eh hehe

    I may have a few further questions shortly, as I'm upgrading my app. with AJAX - so stay alert.

    Best.
    Mark McNeece.



  • harkin

    Hi Brian

    The following is a simple function I wrote in connection with the SOAP envelope I posted above (see my first post in this thread).  There must be a better solution, but this does work just fine:

    Function MSNAPIResults(gQuery, gAppID, gOffset)
     If Trim(gQuery) = "" Then Exit Function

     Dim Qry
     Set Qry = Server.CreateObject("MSXML2.DOMDocument")
     Qry.load Server.MapPath("doMSNSearch.xml")
     Qry.selectSingleNode("//AppID").Text = gAppID
     Qry.selectSingleNode("//Query").Text = gQuery
     Qry.selectSingleNode("//Offset").Text = gOffset

     ' Post the SOAP message.
     Dim soap
     Set soap = Server.CreateObject("MSXML2.ServerXMLHTTP")
     soap.open "post", "
    http://soap.search.msn.com/webservices.asmx", False
     soap.setRequestHeader "Content-Type", "text/xml"
     soap.setRequestHeader "SOAPAction", "Search"
     soap.send Qry ' Dump the results into an XML document.

     Dim Res
     Set Res = Server.CreateObject("MSXML2.DOMDocument")
     Res.loadXML (soap.responseText)

     set root = Res.documentElement
     set nodelist = root.getElementsByTagName("Result")

     ' Parse the XML document.
     Dim rTitle
     Dim rDesc
     Dim rURL
     c = 0
     Dim resArray
     ReDim resArray(49,2)

     For Each Node In Nodelist
      'retrieve the values
      rURL=""
      on error resume next
      rTitle = Node.childNodes.item(0).text
      rDesc = Node.childNodes.item(1).text
      rURL = Node.childNodes.item(2).text
      on error goto 0

      if Trim(rURL)<>"" then
       'its a result
       resArray(c, 0) = rTitle
       resArray(c, 1) = rDesc
       resArray(c, 2) = rURL
       c=c+1
      End If
     Next
     MSNAPIResults = resArray
    End FUNCTION

    I hope this helps  

    By the way, we use this, along with some other very similar functions for the Google Search API, and Yahoo Search API (REST) in an online ranking checker application.  The application isn't publicly available on our site as of course there's restrictions on how many automated queries you can run per day or month with an API key.

    However, we've used very similar coding for our free keyword tool, and meta tag checker.  You can find them on our services page if you wanted to have a look.  Very simple tools indeed, but quite useful nonetheless.  We use them constantly every day as we're a search engine optimisation company.

    Let me know how you get on

    - Mark. 



  • Vadivel_erode

    Hi Mark,

    Thank you kindly for the response. I'll let you know how it works out.

    - Brian


  • Amit Tzafrir

    It appears that I missed this question back in January. My apologies.

    The answer to your question is to use a combination of CultureInfo settings and query operators. For CultureInfo simply set the value to en-GB. To get UK only results, add the loc: operator to each query that you want to scope in this way. For Great Britain, the country/region code is gb, so the user's query would have loc:gb appended to it by your code for the "UK Only" case. You can use any type of UI selection mechanism you like to toggle between "UK Only" and "All Results", removing the query enhancement for the "All Results" case. Please let me know if you need additional information.



  • MSN Search API implemented in ASP only