php5 and issues

Good news about Microsoft allowing access to their MSN Search service through SOAP ! It was definitely about time.
I've been trying to build a MSN Search API client with PHP. I'm using nuSOAP to interface with the SOAP server. However, I'm having a little trouble getting it to work. Just for the record, I've had developed several SOAP clients succesfuly (for example, using Google API).
This is the code that I'm using (of course, where it says 'This is my API key' I'm actually inserting a valid API key; also, the endpoint was taken out of the WSDL file):
define ('NUSOAP_PATH', dirname(__FILE__) . '/nusoap');
define ('MSN_API_ENDPOINT', 'http://soap.search.msn.com:80/webservices.asmx');
define ('MSN_API_KEY', 'This is my API key');
require_once(NUSOAP_PATH . '/nusoap.php');
$query = 'Example Query';
$parameters = array(
'AppID' => MSN_API_KEY,
'Query' => $query,
'CultureInfo' => 'en-US',
'Moderate' => 'Off',
'Requests' => array (
'SourceRequest' => array (
'Source' => 'Web',
'Offset' => 0,
'Count' => 10,
'ResultFields' => 'All'
)
)
);
$soapClient =& new soapclient(MSN_API_ENDPOINT);
$result =& $soapClient->call('Search', $parameters, 'http://schemas.microsoft.com/MSNSearch/2005/09/fex' );
if ($soapClient->getError())
{
echo '<b>ERROR</b>: ' . $soapClient->getError() . '<br />';
echo '<b>DEBUG</b>:<br /><pre>' . $soapClient->debug_str . '</pre>';

$result = false;
}
echo '<hr />';
echo '<pre>';
var_dump($result);
echo '</pre>';

What I'm getting is:
soapenv:Client: Client Error
as a SOAP error.
This is the XML request I send to the server:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:si="http://soapinterop.org/xsd">
<SOAP-ENV:Body>
<ns1:Search xmlns:ns1="http://schemas.microsoft.com/MSNSearch/2005/09/fex">
<SearchRequest>
<AppID xsi:type="xsd:string">This is my API key</AppID>
<Query xsi:type="xsd:string">Example Query</Query>
<CultureInfo xsi:type="xsd:string">en-US</CultureInfo>
<Moderate xsi:type="xsd:string">Off</Moderate>
<Requests>
<SourceRequest>
<Source xsi:type="xsd:string">Web</Source>
<Offset xsi:type="xsd:int">0</Offset>
<Count xsi:type="xsd:int">10</Count>
<ResultFields xsi:type="xsd:string">All</ResultFields>
</SourceRequest>
</Requests>
</SearchRequest>
</ns1:Search>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
And this is the XML response I get:
<?xml version="1.0" encoding="utf-8" ?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<soapenv:Fault>
<faultcode>soapenv:Client</faultcode>
<faultstring>Client Error</faultstring>
<detail>Invalid request</detail>
</soapenv:Fault>
</soapenv:Body>
</soapenv:Envelope>

So I'm getting anInvalid Request. I've tried changing the request several times with no luck. Anybody has a clue? Can anybody give me an example XML request message for a succesful transaction, so I can base my code on that?
Once I get it working I will post a PHP class that will handle the call to MSN Search API transparently for PHP applications.
Thanks !

[5214 byte] By [MarianoIglesias] at [2007-12-24]
# 1
Mariano,

For the record I have tried the samples that come in the SDK from two locations today. Both times I received timeout errors. (I did put my APPID in the correct location.) I suspect there might be availability issues right now!?

-David Sandor

dsandor at 2007-8-31 > top of Msdn Tech,Windows Live Developer Forums,Windows Live Search: Development...
# 2
The XML request should have the following changes:

<Request> instead of <SearchRequest>
Request is the object name, whereas SearchRequest is the object type.

<SafeSearch> instead of <Moderate>
Moderate is actually one of three values that the SafeSearch parameter can take. It's the default value.

The rest looks good. Hope that helps :).

--Navin

NavinJoy at 2007-8-31 > top of Msdn Tech,Windows Live Developer Forums,Windows Live Search: Development...
# 3
This version works


$query = 'Example Query';

$parameters = array(
'AppID' => MSN_API_KEY,
'Query' => $query,
'CultureInfo' => 'en-US',
'SafeSearch' => 'Off',
'Requests' => array (
'SourceRequest' => array (
'Source' => 'Web',
'Offset' => 0,
'Count' => 10,
'ResultFields' => 'All'
)
)
);

$soapClient =& new soapclient(MSN_API_ENDPOINT);

$result =& $soapClient->call('Search', array("Request"=>$parameters), 'http://schemas.microsoft.com/MSNSearch/2005/09/fex' );



test it here : http://www.quodlibet.be/msnapi.php
quodlibet at 2007-8-31 > top of Msdn Tech,Windows Live Developer Forums,Windows Live Search: Development...
# 4
quodlibet wrote:
This version works
test it here : http://www.quodlibet.be/msnapi.php

Yes it does ! Good call quodlibet ! Enclosing the parameters as array ('Request' => $parameters) it was something that I've already tried, but I haven't also tried changing Moderate to SafeSearch. That was the trick.
I will shortly post the class here. Thanks for your help guys !
MarianoIglesias at 2007-8-31 > top of Msdn Tech,Windows Live Developer Forums,Windows Live Search: Development...
# 5
As promised, I just created the class to interact with MSN Search API with PHP.
You can see its sourcecode, and a link to a working version, in this post in my blog, entitled MSN Search API PHP Client.
MarianoIglesias at 2007-8-31 > top of Msdn Tech,Windows Live Developer Forums,Windows Live Search: Development...
# 6
(Sorry for the formatting, I was unable to find any help on this forum.)
Hi.

I'm trying to use MSN api, too.

I'm working on a port of the python API already made for Google : http://pygoogle.sourceforge.net/
Well. I'm too receiving the same Invalid request error, after sending, exactly (plus linebreaks for readability) :
BAD REQUEST :

<?xml version="1.0" encoding="UTF-8"?>

<soap-env:envelope soap-env:encodingstyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/1999/XMLSchema">

<soap-env:body>

<ns1:search xmlns:ns1="http://schemas.microsoft.com/MSNSearch/2005/09/fex" soap-enc:root="1">

<request>

<query xsi:type="xsd:string">

test

</query>

<safesearch xsi:type="xsd:string">

Off

</safesearch>

<requests>

<sourcerequest>

<count xsi:type="xsd:int">

10

</count>

<source xsi:type="xsd:string">

Web

</source>

<resultfields xsi:type="xsd:string">

All

</resultfields>

<offset xsi:type="xsd:int">

0

</offset>

</sourcerequest>

</requests>

<cultureinfo xsi:type="xsd:string">

en-US

</cultureinfo>

<appid xsi:type="xsd:string">

1C53F41886E25BCA7D36F4D84B87B7B552178A0A

</appid>

</request>

</ns1:search>

</soap-env:body>

</soap-env:envelope>
Whereas this code, built from the PHP we're talking about, works perfectly well :
GOOD REQUEST

<?xml version="1.0" encoding="ISO-8859-1"?>

<soap-env:envelope soap-env:encodingstyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/">

<soap-env:body>

<ns7540:search xmlns:ns7540="http://schemas.microsoft.com/MSNSearch/2005/09/fex">

<request>

<appid xsi:type="xsd:string">

1C53F41886E25BCA7D36F4D84B87B7B552178A0A

</appid>

<query xsi:type="xsd:string">

test

</query>

<cultureinfo xsi:type="xsd:string">

en-US

</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">

10

</count>

<resultfields xsi:type="xsd:string">

All

</resultfields>

</sourcerequest>

</requests>

</request>

</ns7540:search>

</soap-env:body>

</soap-env:envelope>
The differences are :

- the encoding

- the year of xmlns:xsd and xmlns:xsi

- the soap-enc attribute in the <ns> tag (even when I remove it, I still get the error)

- the order of elements in the <request> tag
That's all. All and all. And I get an error.
Does anyone of you have the slightest idea of what's happening ?

Any help would be greatly appreciated.

lagroue at 2007-8-31 > top of Msdn Tech,Windows Live Developer Forums,Windows Live Search: Development...
# 7
Hello, i've gotten php5 to connect to the api, and I'm now trying to write a simple ranking script...
I got my code working, but only for the first 10 results...anything else, and it won't work...it just regurgitates the first 10 results again when processing through my FOR logic ..apparently it's not passing the sourcerequest arrays....
$request = array('Request' => array(
'AppID' => 'xxxxx',
'Query' => $query,
'CultureInfo' => 'en-US',
'SafeSearch' => 'Strict', 'Flags' => '',
'Location' => '',
'Requests' => array(
'SourceRequest' => array(
'Source' => 'Web',
'Offset' => $startIndex,
'Count' => 10,
'ResultFields' => 'All'))));i believe the problem is in the passing of the source request array, because it only send the default stuff whether i try to change to count field or i try to change the offset.
I know the rest of my code is tight....it works well for the google api....
any suggestions? i can post the entire code if necessary...
EdwinJeffcoat at 2007-8-31 > top of Msdn Tech,Windows Live Developer Forums,Windows Live Search: Development...
# 8
I ran into this problem too but it turned out to be a problem with PHP SOAP not MSN. (If you run a packet sniffer on the outbound traffic, you'll see that it's actually asking for 10 results instead of 50.) NuSOAP, on the other hand, works.
http://www.richardkmiller.com/files/msnsearch_nusoap.html (works)
http://www.richardkmiller.com/files/msnsearch_php5soap.html (doesn't work)
I posted a message to the PHP SOAP mailing list and one of the developers said it is a bug that he fixed in the latest release of PHP 5. Here is his message:
http://news.php.net/php.soap/2016
Hope this helps,
Richard
RichardMiller at 2007-8-31 > top of Msdn Tech,Windows Live Developer Forums,Windows Live Search: Development...
# 9
Is there any way to use the MSNSearch web service using the WSDL file, currently I cant get either NuSOAP or the PHP 5 SOAP Extension to work using only the WSDL. To use any of them I have to specify the endpoint for the service, something which the WSDL file is supposed to handle. As well as the setting of the namespace.

Compared to the google soap wsdl the msn search one seems overly complicated.

Also just another point, I have got a successful response back using when specifying the endpoint, but the returned document I cant get to be parsed by the simplexml extension. I havent had these problems with any other web service I have tried to work with.

Before anyone tells me to use non-WSDL mode as that works. I need to use WSDL mode so that I can utilise class mapping with the PHP 5 SOAP Extension.

GeoffGarside at 2007-8-31 > top of Msdn Tech,Windows Live Developer Forums,Windows Live Search: Development...
# 10
got all that working...(actually some time ago)

now I'm wanting to expand what I'm using it for (ranking) and include the cache date, which is found in the DateTime tag. the problem that I would like to solve is being able to do both in the same query, but I can't seem to build the ResultFields filter correctly.

I've looked all over the net, but most scripts just use the all tag, which doesn't include the DateTime field. anybody tried to do this, or will I just have to suck it up and run two queries.

Ed

EdwinJeffcoat at 2007-8-31 > top of Msdn Tech,Windows Live Developer Forums,Windows Live Search: Development...
# 11

I

haven't been able to find any php code which uses cURL rather than SOAP

to interact with the LIVE search api service so I have written some and

published it on my website.

Feel free to check it out and leave comments :)

http://www.onlinehoster.com/blog/msnlive-api-scraper-script/

Stephen. at 2007-8-31 > top of Msdn Tech,Windows Live Developer Forums,Windows Live Search: Development...
# 12
Is it possible to desingn a keyword position tool using PHP and nusoap or pear soap classes.
I am new to working with SOAP, where can i find more material regarding this?
I hve PHP4 installed on my server.

free seo tips, guidelines

RishirajSingh at 2007-8-31 > top of Msdn Tech,Windows Live Developer Forums,Windows Live Search: Development...

Windows Live Developer Forums

Site Classified