Friday, August 26, 2005

billbiter.co.uk

Add to Delicious Digg this links to this post -

Here we go, we have just launched billbiter.co.uk - ok, loads of bugs & functionalities to add. but why keeping it on staging while indexation will take about as much time as what it takes to make the site pretty.

We redirect to pages ranked first in google for a specific query - how do we do that? very simple class using google API.

You can do the same easily (just collect your API key first):


<?php


require_once('../include/soap/nusoap.php');

class
Google {

    var
$parameters;

    var
$soapoptions;

    var
$max_retries;


    function
Google($key, $max_retries){


        
$this->soapclient = new soapclient('http://api.google.com/GoogleSearch.wsdl', 'wsdl');

        
$this->max_retries = $max_retries;

        
$this->parameters = array (

            
'key' => $key, // the Developer's key

            
'q' => '',         // the search query


            
'start' => 0,          // the point in the search results should Google start

            
'maxResults' => 1,     // the number of search results (max 10)

            
'filter' => false,     // should the results be filtered?


            
'restrict' => '',

            
'safeSearch' => false,

            
'lr' => '',

            
'ie' => '',


            
'oe' => ''

            
);

    }

    function
Google_do_search($query=NULL){

        if (
$query) $this->parameters["q"] = $query;


        
$this->result = $this->soapclient->call('doGoogleSearch', $this->parameters);

        if (!
$this-result)


            
$this->Google_retry();

        return
TRUE;

    }

    function
Google_retry(){

        
$this->result = false;


        
$retry_count = 0;

        while( !
$this->result && $retry_count < $this->max_retries ){

              
$this->result = $this->Google_do_search( $query, $key, $num );


            if( !
$this->result ) $this->error = "Attempt".$retry_count." failed<br>\n";


            
$retry_count++;

        }

        return
TRUE;

    }

    function
Google_url(){

        return
$this->result["resultElements"][0]["URL"];


    }

}

?>

0 Comments:

Post a Comment

Links to this post:

Create a Link

<< Home