Domain Empire

How to use Google API - Number of indexed pages

Spaceship Spaceship
Watch
Impact
68
I hope that this guide will help the new API developers in gaining a better understanding of the Google API so as to develop their own applications.

Stuff you need before coding

1. This guide uses NuSOAP class as the interaction with the Google web services. You can download the class at:
http://sourceforge.net/projects/nusoap/

2. A Google API license key is required. You can apply it here:
https://www.google.com/accounts/New...ekey&followup=http://api.google.com/createkey

3. This guide is short and coded in PHP to ensure an easier understanding.

Live Demo

A live demo can be found at:
http://www.useseo.com/google-api-demo.php

The script is also available for download. Simply change the Google key so that the script can work.

Coding
The following codes are the essential part of the script once the form button is pressed:
PHP:
<?php  
require_once('lib/nusoap.php'); // include the nusoap class

if(isset($_POST['submit'])) { // upon button pressed
     
  //trim the user's url
  $qurl=trim($_POST['url']);  
  
  $mq='site:'.$qurl;
   
   $parameters = array(
	'key'=> 'Your_Google_API_Key',
	'q'=> $mq,
	'start'=> '0',
	'maxResults'=>'10',
	'filter'=> 'false',
	'restrict'=>'',
	'safeSearch'=>'false',
	'lr'=>'',
	'ie'=>'',
	'oe'=>''
	);
	
	//Create a new soap client, feeding it googlesearch.wsdl
	$soapclient=new soapclient('http://api.google.com/GoogleSearch.wsdl','wsdl');
	
	//save the results into $results array
	$results = $soapclient->call('doGoogleSearch',$parameters);   
	
	//save the total number of pages indexed 
	$no_pages=$results['estimatedTotalResultsCount'];	
} 
?>

Code explanation
The first line includes the NuSOAP class for later usage.
The url keyed in by the user was appended with the site: operator on the left and saved in the parameter array.

Further details of the parameters can be found at: http://code.google.com/apis/soapsearch/reference.html#2_1

Finally, the results are saved in the $no_pages variable for display.

Other possible usage
As we only used the estimatedTotalResultsCount element here, there are many other elements that you can make use of to develop other applications. The format of the search response from Google can be found at:
http://code.google.com/apis/soapsearch/reference.html#3_1

Hope it helps :)
 
1
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
Nice tutorial.

It realy helped.

Thanks for sharing!
 
0
•••
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back