Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Google API help

by inblosam (Monk)
on Aug 12, 2006 at 20:42 UTC ( [id://567052]=perlquestion: print w/replies, xml ) Need Help??

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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://567052]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2024-04-19 04:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found