Update friend requests on Twitter (only) to support cursors instead of pages
authorDan Boger <zigdon@irc.peeron.com>
Thu, 22 Oct 2009 16:37:02 +0000 (09:37 -0700)
committerDan Boger <zigdon@irc.peeron.com>
Thu, 22 Oct 2009 16:37:02 +0000 (09:37 -0700)
twirssi.pl

index 15b64780fcd97816932f48550cab261f99a04cbe..0abb396b1756e7acf3371b3e4f880d68da3b89fe 100644 (file)
@@ -792,18 +792,26 @@ sub cmd_upgrade {
 
 sub load_friends {
     my $fh   = shift;
+    my $cursor = -1;
     my $page = 1;
     my %new_friends;
     eval {
-        while (1)
+        while ($page < 11 and $cursor ne "0")
         {
             print $fh "type:debug Loading friends page $page...\n"
               if ( $fh and &debug );
-            my $friends = $twit->friends( { page => $page } );
-            last unless $friends;
+            my $friends;
+            if (ref $twit =~ /^Net::Twitter/) {
+                $friends = $twit->friends( { cursor => $cursor } );
+                last unless $friends;
+                $cursor = $friends->{next_cursor};
+                $friends = $friends->{users};
+            } else {
+                $friends = $twit->friends( { page => $page } );
+                last unless $friends;
+            }
             $new_friends{ $_->{screen_name} } = time foreach @$friends;
             $page++;
-            last if @$friends == 0 or $page == 10;
         }
     };