locked
Problem running Live search API example on Apache web server + PHP RRS feed

  • Question

  •  

    Hi,

     

    I'm hoping someone can help me.  I signed up for an AppID and followed all of the instructions in order to get the Live search API php example to work.  However when I run WindowsLiveSearch.php and try to search for something, I receive the following error.  I've tried using a different linux distro and receive the same error.

     

    I'm running the latest PHP and Apache so it's not that and I've installed all of the php plugins including the SOAP client/server plugin.

     

    The error i'm receiving is below, please help anyone?

     

     

     

    SoapFault exception: [soapenv:Client] Client Error in /var/www/html/PHP/Search.php:571 Stack trace: #0 [internal function]: SoapClient->__call('Search', Array) #1 /var/www/html/PHP/Search.php(571): SoapClient->Search(Object(Search)) #2 {main}

     

     

     

    I know the live search API php example says it was made for IIS and tested on IIS server but I saved the files to my Hostmonster shared hosting account and they work fine there so that's what the strange part is.

     

    Could it have anything to do with me specifying my home IP address instead of a website when I applied for my AppDev ID?   Any help at all, much appreciated.

     

    Thanks

     

    Ricky,

    Wednesday, November 26, 2008 2:34 AM

Answers

  • The PHP code out there is for API 1.1. It was actually built on Linux + Apache at the time. The issue is that the new API is quite different from the older version.

     

    For API 2.0 we don't have official PHP samples out (still working on them - it will be a while longer).

    A code snippet you can start with is this:

     

    Code Snippet
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html>
    <head>
      '>http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html>
    <head>
      ; <title>Live Search API 2.0 through PHP</title>
    </head>
    <body>
    <?php
    $APPID = "Your AppID here";
    ?>
    <form method="post" action="<?php echo $PHP_SELF;?>">
    <input type="text" id="searchBox" name="searchBox" value="<?php
            if (isset($_POST['searchBox'])){
             echo($_POST['searchBox']);
            }
      else {
             echo('Microsoft');
       }
        ?>"/>
        <input type="submit" value="Search" name="submit" id="searchButton" />
                    <?php
        if (isset($_POST['submit']))
                    {
         $request = 'http://api.search.live.net/json.aspx?Appid=' . $APPID . '&sources=web&query=' . urlencode( $_POST["searchBox"]);
         $response  = file_get_contents($request);
         $jsonobj  = json_decode($response);
         echo('<ul ID="resultList">');                   
         foreach($jsonobj->SearchResponse->Web->Results as $value)
         {
          echo('<li class="resultlistitem"><a href="' . $value->Url . '">');
          echo('<h3>' . $value->Title . '</h3></a>');
          echo('<p>' . $value->Description . '</p>');
                        }
         echo("</ul>");
        }
                    ?>
    </form>
    </body>
    </html>

     

     

    (discalimer: I have not run it on a non-Windows machine yet, but it runs fine with PHP 5 on IIS)

     

    HTH

     

    --Alessandro

    Thursday, November 27, 2008 6:29 AM