NuSphere Forums Forum Index
NuSphere Forums
Reply to topic
Google Seach API example
Site Admin

Joined: 13 Jul 2003
Posts: 8342
Reply with quote
Code:
<html>
<head>
  <title>Google SOAP Search API example</title>
</head>
<body>
<?php

require_once('nusoap.php');

# Set parameters
$parameters = array(
  'key'=> 'obtain your own google api key at http://code.google.com/apis/soapsearch/ and put it there',
  'q' => 'NuSphere PHP IDE' ,
  'start' => '0',
  'maxResults' => '10',
  'filter' => 'false',
  'restrict' => '',
  'safeSearch' => 'false',
  'lr' => '',
  'ie' => '',
  'oe' => ''
);

// creating
$soapclient = new soapclient('http://api.google.com/GoogleSearch.wsdl', 'wsdl');
$err = $soapclient->getError();
if ($err) {
  echo '<h2>Failed to access WSDL</h2><pre>' . $err . '</pre>';
} else {
  // actual SOAP request
  $results = $soapclient->call('doGoogleSearch',$parameters,'urn:GoogleSearch');
  $err = $soapclient->getError();
  if ($err) {
    echo '<h2>SOAP call error</h2><pre>' . $err . '</pre>';
  } else {
    if ($soapclient->fault) {
      echo '<h2>Fault</h2><pre>';
      print_r($results);
      echo '</pre>';
    } else {
      echo '<h2>Results:</h2>';
      foreach ($results['resultElements'] as $val) {
        echo "<a href=" . $val['URL'] . ">" . $val['title'] . "</a><br>";
        echo $val['snippet'] . "<br>";
        echo $val['URL'] . "<br>";
        echo "<br>";
      }
    }
  }
}


This example shows how to use NuSoap for running queries using Google API.
Before using, please make sure you updated the 'key' element in the $parameters with a valid Google API key you obtained from there http://code.google.com/apis/soapsearch/
View user's profileFind all posts by dmitriSend private messageVisit poster's website
Google Seach API example
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT - 5 Hours  
Page 1 of 1  

  
  
 Reply to topic