Search code examples
perltwitter

Using Net::Twitter::Lite::WithAPIv1_1 works for small searches - sometimes


I am trying to search for tweets about Art Trails with a Perl program using the Net::Twitter::Lite::WithAPIv1_1 module. Sometimes it works sometimes it returns nothing but 200: OK. The smaller the number of results I request the more likely it is to work. It is not an issue with the Twitter limits. Could it be something to do with timing of the data return?

use Net::Twitter::Lite::WithAPIv1_1;

my $nt = Net::Twitter::Lite::WithAPIv1_1->new(
  traits   => [qw/OAuth API::RESTv1_1/],
  consumer_key        => $c1,
  consumer_secret     => $c2,
  access_token        => $c3,
  access_token_secret => $c4,
  ssl  => 1,
  legacy_lists_api => 0
  );

my $maxresults = 10;

eval {
my $r = $nt->search('"art walk" OR "artists walk" OR "art walks" OR "artist walks" OR "artist trail" OR "artist trails" OR "art trail" OR "art trails" -filter:retweets' ,{ count => $maxresults});

use Data::Dumper;
print Dumper $r;

};

print $@;

Solution

  • I could not figure out what was going on, but I got around the problem by putting the request into a loop and retrying the request with ever diminishing max results. And it seems that I am now consistently getting a result.