MSN Search API

Like other search engines, MSN made public a few APIs, including the most important: web search. They are using SOAP and could be used online from any other programming language and platforms.

As usual, first step is registration. You have to register your free application ID, needed in your web requests. MSN provided some MSDN help files and samples, but only for C# & VB.NET.

Our example here will be in PHP with NuSOAP. See it at work in this small demo (popup window). The PHP source code is this (only for MSN interrogation part):

# Use the NuSOAP php library
require_once('nusoap.php');

# Set parameters
$parameters = array(
  'AppID'=>'…your AppID…',
  'Query' => $_POST['key'],
  'CultureInfo' => 'en-US',
  'SafeSearch' => 'Off',
  'Requests' => array (
     'SourceRequest' => array (
         'Source' => 'Web',
         'Offset' => 0,
         'Count' => 10,
         'ResultFields'  => 'All' )
      )
   );

$soapclient =
    new soapclient('http://soap.search.msn.com/webservices.asmx');

$results = $soapclient->call('Search',array("Request"=>$parameters));

if( is_array($results['Responses']) ) {
  echo "<p><b>Your MSN query for '" . $_POST['key'] . "' found "
 . $results['Responses']['SourceResponse']['Total'] . ":</b></p>";
  foreach ( $results['Responses']['SourceResponse']['Results'] as $result ) {
 echo "<p><a href='" . $result['Url'] .
  "' target='_blank'>".$result['Title'].
  "</a><br />".$result['Description'].
  "<br />". $result['DisplayUrl']."</p>";
  }
 }
}

Don't forget to replace your AppID.

As you can see, the URL for web service is http://soap.search.msn.com/webservices.asmx and function name is 'Search'. You have to build proper parameters before calling function, most important 'Query', 'Source' (for web or local search), 'Offset' and 'Count' (how many results).

Results are returned as associative arrays, containing other arrays, for instance $results['Responses']['SourceResponse']['Results']['Url']. Hint: to see all fields, replace displaying part with a simple

print_r($results).

Usage limit is quite large: up to 10,000 queries a day. For more options see MSDN documentation.

Leave a Comment

You must be logged in to post a comment.