On Tue Feb 16 08:56:45 2010, psmitty wrote:
Show quoted text> Recently the Net::Twitter::Search module is failing to return any
> results for the geocode tag.
>
> Here is my script:
>
> use strict;
> use warnings;
>
> use Net::Twitter::Search;
> use Geo::Coder::Bing;
>
> my $town = 'my town';
> my $state = 'my state';
> my $zip = 'my zip';
>
> my $near = "$town, $state, $zip";
> my $units = 'mi';
>
> my $twit = Net::Twitter::Search->new;
>
> my $geocoder = Geo::Coder::Bing->new;
> my $location = $geocoder->geocode(
> location => $near
> );
>
> my $latitude = $location->{BestLocation}->{Coordinates}->{Latitude};
> my $longitude = $location->{BestLocation}->{Coordinates}->{Longitude};
>
> my %seen = ();
> for( 1..10 ) {
>
> my $result = $twit->search( { geocode
> => "$latitude,$longitude,$units", page => $_, rpp => 100 } );
There are 2 problems with this search. First, Twitter doesn't return
results for just the geocode parameter, alone. You also need a "q"
parameter. Second, the $units needs to include the number of units, not
just the unit-of-measure.
Try: ->search({ q => "pizza", geocode =>
"$latitude,$longitude,25$units", rpp => 100 });
There's also a Twitter bug here, in my opinion. Rather than returning an
error in JSON, Twitter is returning a 500 response code and an unhelpful
HTML page.
You should consider using Net::Twitter, rather than
Net::Twitter::Search. The latter is really for backwards compatibility
with the original Net::Search module before the Search API was
integrated into Net::Twitter. Net::Twitter throws exceptions on error
rather than just returning undef, which would have made it more obvious
that an error occurred rather than just a lack of results.
use Net::Twitter;
use Try::Tiny;
$twit = Net::Twitter->new(traits => ['API::Search']);
try {
$result = $twit->search({ ... });
}
catch {
warn $_; # would have printed "Internal Server Error: 500"
};
I'm going to leave this bug open while I consider what, if anything, to
do with it. Better documentation would be helpful. I could do some
parameter checking, but I have avoided that in the past so that as
Twitter changes their API (adding, dropping, or changing parameter
requirements), no code changes to Net::Twitter are required to
accommodate them. Perhaps some diagnostics on failure.
-Marc