Ignore:
Timestamp:
Jul 22, 2009, 8:40:13 PM (15 years ago)
Author:
Nelson Elhage <nelhage@mit.edu>
Branches:
master, release-1.10, release-1.7, release-1.8, release-1.9
Children:
0b13bbc
Parents:
efcd223
Message:
Don't use verify_credentials.

Twitter apparently ratelimits verify_credentials far more than other
requests, so just ask for our timeline to verify credentials, instead of
relying on verify_credentials.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • lib/BarnOwl/Module/Twitter/Handle.pm

    refcd223 ra8a0b0a  
    6161    $self->{twitter}  = Net::Twitter->new(%twitter_args);
    6262
    63     if(!defined($self->{twitter}->verify_credentials())) {
     63    my $timeline = $self->{twitter}->friends_timeline({count => 1});
     64
     65    if(!defined($timeline)) {
    6466        $self->fail("Invalid credentials");
    6567    }
    6668
    67     unless(defined($self->{last_id})) {
    68         eval {
    69             $self->{last_id} = $self->{twitter}->friends_timeline({count => 1})->[0]{id};
    70         };
    71         $self->{last_id} = 1 unless defined($self->{last_id});
    72     }
    73 
    74     unless(defined($self->{last_direct})) {
    75         eval {
    76             $self->{last_direct} = $self->{twitter}->direct_messages()->[0]{id};
    77         };
    78         $self->{last_direct} = 1 unless defined($self->{last_direct});
    79     }
     69    eval {
     70        $self->{last_id} = $timeline->[0]{id};
     71    };
     72    $self->{last_id} = 1 unless defined($self->{last_id});
     73
     74    eval {
     75        $self->{last_direct} = $self->{twitter}->direct_messages()->[0]{id};
     76    };
     77    $self->{last_direct} = 1 unless defined($self->{last_direct});
    8078
    8179    eval {
Note: See TracChangeset for help on using the changeset viewer.