[PHP] Google APIs with PHP
Hi all, I am new to PHP and just tested out using NuSoap to query Google database. The code is written by Harish Kamath. However, it doesn't work without error message. The web server I used support PHP. Also I downloaded the required nusoap.php class file and put it in the same directory with nusearch.php, which query Goodgle database and I have Google's licence key for its APIs. The code is as following: if (!$_POST['q']) { ?> Search Search term: // create a instance of the SOAP client object $soapclient = new soapclient("http://api.google.com/search/beta2";); // uncomment the next line to see debug messages // $soapclient->debug_flag = 1; print("Before params"); // testing // set up an array containing input parameters to be // passed to the remote procedure $params = array( 'key' => 'LHZMFvNQFHJ/jGT0d6N8Iu83QVsz49rr', // Google license key 'q' => $_POST['q'], // search term 'start' => 0, // start from result n 'maxResults' => 10, // show a total of n results 'filter' => true, // remove similar results 'restrict' => '', // restrict by topic 'safeSearch' => true, // remove adult links 'lr' => '', // restrict by language 'ie' => '', // input encoding 'oe' => ''// output encoding ); print("before invoke the doGoogleSearch method"); // invoke the method on the server $result = $soapclient->call("doGoogleSearch", $params,"urn:GoogleSearch", "urn:GoogleSearch"); print("before printing results"); // print the results of the search if ($result['faultstring']) { ?> Error } else { ?> Search Results Your search for produced hits. print("before displaying result"); if (is_array($result['resultElements'])) { foreach ($result['resultElements'] as $r) { echo "" . $r['title'] . ""; echo ""; echo $r['snippet'] . "(" . $r['cachedSize'] . ")"; echo ""; } } ?> Would be very much appreciated if someone can help me out. Thanks, Daniel _ Get 10Mb extra storage for MSN Hotmail. Subscribe Now! http://join.msn.com/?pgmarket=en-hk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Google APIs with PHP
Sorry about it. I should include the code as attachment. Daniel _ Get 10Mb extra storage for MSN Hotmail. Subscribe Now! http://join.msn.com/?pgmarket=en-hk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Problem execucting nusoap.php
Hi, I am new to php and tried to test googlesearch.php file (as attachment) from Chris Petersen. Which invokes nusoap.php file. I have all the necessary class files that nusoap.php included and put in the same directory with googlesearch.php and nusoap.php file. Also I have Google's licence key as well. But when executed googlesearch.php. It only displays the documentation of class.soapclinet.php and nothing else. Could anybody tell me what is the problem? Please help. Thanks, Daniel _ Get 10Mb extra storage for MSN Hotmail. Subscribe Now! http://join.msn.com/?pgmarket=en-hk Google API */ require_once("nusoap.php"); class GoogleSearchResults { var $estimatedTotalCount; var $searchTime; var $startIndex; var $endIndex; var $results; var $directories; } class GoogleSearchResult { var $cachedSize; var $hostName; var $snippet; var $summary; var $title; var $url; } function googleSearch($query, $startIndex) { $soapclient = new soapclient("GoogleSearch.wsdl", "wsdl"); $proxy = $soapclient->getProxy(); $result = $proxy->doGoogleSearch("wzMXCPhQFHIoNdE1l1x/hsudArv9AceZ", $query, $startIndex, 10, "false", "", "false", "", "latin1", "latin1"); $returnVal = new GoogleSearchResults(); $returnVal->estimatedTotalCount = $result["estimatedTotalResultsCount"]; $returnVal->searchTime = $result["searchTime"]; $returnVal->startIndex = $result["startIndex"]; $returnVal->endIndex = $result["endIndex"]; $rerurnVal->results = array(); $resultElements = $result["resultElements"]; for($i=0; $icachedSize = $resultElements[$i]["cachedSize"]; $entry->hostName = $resultElements[$i]["hostName"]; $entry->snippet = $resultElements[$i]["snippet"]; $entry->summary = $resultElements[$i]["summary"]; $entry->title = $resultElements[$i]["title"]; $entry->url = $resultElements[$i]["URL"]; $returnVal->results[$i] = $entry; } return $returnVal; } ?> -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Help: undefined function: getproxy()
Hello there, I tested GoogleAPI with PHP and soap. But got an error message when running the googlesearch.php file(http://127.0.0.1/googlesearch.php). Fatal error: Call to undefined function: getproxy() in C:\Program Files\Abyss Web Server\htdocs\googlesearch.php on line 9 My OS is Windows XP with lastest Abyss and PHP 4.3.2 installed. I have all soap classes in /htdocs folders with GoogleSearch.wsdl and googlesearch.php Here is the googlesearch.php file: $key = 'wzMXCPhQFHIoNdE1l1x/hsudArv9AceZ'; $query = 'cat'; $wsdlurl = './GoogleSearch.wsdl'; $WSDL = new SOAP_WSDL($wsdlurl); $client = $WSDL->getProxy(); $response = $client->doGoogleSearch( $key,$query,0,4, false,'',false,'','',''); foreach($response->resultElements as $result) { echo ''; echo $result->title."\n"; echo $result->snippet."\n"; } ?> Please help. By the way, other php file works fine. Thanks in advance. Daniel _ Get 10Mb extra storage for MSN Hotmail. Subscribe Now! http://join.msn.com/?pgmarket=en-hk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php