PHP5 and Microsoft Live Search 2.0

I'm trying to use Live Search 2.0, but even a simple example doesn't seem to work. Microsoft only has sample code for version 1.1, and they don't issue the AppID for that version.

Here I am trying:

<?php
$server = new SoapClient('http://soap.search.msn.com/webservices.asmx?wsdl');

class Search {
    public $Request;
}

class SearchRequest {
    public $AppID;
    public $Query;
    public $CultureInfo;
    public $SafeSearch;
    public $Flags;
    public $Location;
    public $Requests;
}

class SourceRequest {
    public $Source;
    public $Offset;
    public $Count;
    public $FileType;
    public $SortBy;
    public $ResultFields;
    public $SearchTagFilters;
}

$searchRequest = new SourceRequest();
$searchRequest->Source = 'Web';
$searchRequest->Offset = 0;
$searchRequest->Count = 5;
$searchRequest->ResultFields = 'All SearchTagsArray';

$request = new SearchRequest();
$request->AppID = '...';
$request->Query = 'Bill Gates';
$request->CultureInfo = 'en-US';
$request->SafeSearch = 'Off';
$request->Flags = '';
$request->Requests = array($searchRequest);

$search = new Search();
$search->Request = $request;

$server->Search($search);
?>

      

The AppID is correct in the code: I just erased it from here. I am getting the following error:

Array ( [0] => SearchResponse Search(Search $parameters) )
Fatal error: Uncaught SoapFault exception: [soapenv:Client] Client Error in /Users/thardas/Sites/vt9/widgets/ms_livesearch.php:41
Stack trace:
#0 [internal function]: SoapClient->__call('Search', Array)
#1 /Users/thardas/Sites/vt9/widgets/ms_livesearch.php(41): SoapClient->Search(Object(SearchRequest))
#2 /Users/thardas/Sites/vt9/index.php(23): include('/Users/thardas/...')
#3 {main} thrown in /Users/thardas/Sites/vt9/widgets/ms_livesearch.php on line 41

      

0


source to share


2 answers


You can start by using a suitable apap url for 2.0. This is now " http://api.search.live.net/search.wsdl?AppID=YourAppId " taken from ( http://msdn.microsoft.com/en-us/library/dd250965.aspx )

You can also use the new JSON api from php.



$appid = 'Your app id';
$searchitem = 'PHP Manual';
    $request = 'http://api.search.live.net/json.aspx?Appid=' . $appid . '&sources=web&query=' . urlencode( $searchitem);
    $response  = file_get_contents($request);
    $jsonobj  = json_decode($response);
    foreach($jsonobj->SearchResponse->Web->Results as $value)
    {
    //$value->Url
    //$value->Title
    //$value->Description
    } 

      

And finally theres the xml api you can also find a link to msdn and it can be obtained in much the same way as json, you just need to decode it differently.

+2


source


Sample code for API 2.0 is on MSDN, but we don't have the full PHP code yet. The first code example (very similar to the one you already received) is included in a blog post on the Live Search Developers Blog



You may be aware that PHP 5.2.6 has some SOAP issues - the Live Search service seems to be affected in both 1.1 and 2.0. Simplest workaround is to use a different interface (JSON or XML)

0


source







All Articles