inblosam has asked for the wisdom of the Perl Monks concerning the following question:

I am using googly.pl that I found for connecting through the Google API. I had some other code that I wrote that was just about exactly the same, but both have the same issue. After reading several forums and such it seems that it is a problem on Google's side where not every request actually works. However, I can't figure out how to call the doGoogleSearch again if it doesn't work. I would like it to try say 10 times first, and then exit if it is still not working. Any suggestions? Here is the code:
#!/usr/local/bin/perl # googly.pl # A typical Google Web API Perl script. # Usage: perl googly.pl <query> # Your Google API developer's key. my $google_key='MYGOOGLEAPIWASHERE'; # Location of the GoogleSearch WSDL file. my $google_wdsl = "/pathonserver/GoogleSearch.wsdl"; use strict; # Use the SOAP::Lite Perl module. use SOAP::Lite; # Take the query from the command line. my $query = shift @ARGV or die "Usage: perl googly.pl <query>\n"; # Create a new SOAP::Lite instance, feeding it GoogleSearch.wsdl. my $google_search = SOAP::Lite->service("file:$google_wdsl"); # Query Google. my $results; $results = $google_search -> doGoogleSearch( $google_key, $query, 0, 10, "false", "", "false", "", "latin1", "latin1" ); # No results? if ($results eq undef) { print "No Go Budddddy!\n"; } exit unless $results; @{$results->{resultElements}} or exit; # Loop through the results. foreach my $result (@{$results->{resultElements}}) { # Print out the main bits of each result print join "\n", $result->{URL}, $result->{snippet} || 'no snippet', "\n"; }


Michael

Replies are listed 'Best First'.
Re: Google API help
by andyford (Curate) on Aug 13, 2006 at 12:23 UTC
    Maybe take a step back and peek at your errors?
    Here's what I'd start with after a quick glance at the SOAP::Lite docs.
    (absolutely untested)
    if ($results->fault) { print "Problem! ".$result->faultcode.": ". $result->faultstring; }
    Something like this should be in your production code anyways.