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

In reply to Google API help by inblosam

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.