Seems like twitter has changed the JSON-api for retrieving friends and followers. They are now using "cursors" instead of "page" to paginate the requests.
I guess one could use the api-calls from Net::Twitter in a better way, but I just needed a quick hack to get it up and running again.
The symptoms when hitting this is that if you have more than 100 followers or follow more than 100 people, you will not get all friends joining
twitter, and you will hit twitters api-limit when connecting to tircd.
Here is an ugly patch, a better perl-hacker will probably fix this in a better way:
--- tircd.pl.orig 2009-08-07 09:49:21.000000000 +0200 +++ tircd.pl 2009-12-04 12:54:57.000000000 +0100
@@ -941,30 +947,38 @@
#get list of friends
my @friends = ();
- my $page = 1;
- while (my $f = eval { $heap->{'twitter'}->friends({page => $page}) }) {
- last if @$f == 0;
- push(@friends,@$f);
- $page++;
+ my $cursor = -1;
+ while (my $f = eval { $heap->{'twitter'}->friends({'cursor' => $cursor})
}) {
+ $cursor = $f->{'next_cursor'};
+ foreach my $user ($f->{'users'}) {
+ foreach my $u (@{$user}) {
+ push(@friends, $u);
+ }
+ }
+ last if $cursor == 0;
}
#if we have no data, there was an error, or the user is a loser with no friends, eject 'em - if ($page == 1 && $heap->{'twitter'}->http_code >= 400) { + if ($cursor == -1 && $heap->{'twitter'}->http_code >= 400) { $kernel->call($_[SESSION],'twitter_api_error','Unable to get friends list.'); return; }
#get list of friends
my @followers = ();
- my $page = 1;
- while (my $f = eval { $heap->{'twitter'}->followers({page => $page}) }) {
- last if @$f == 0;
- push(@followers,@$f);
- $page++;
+ my $cursor = -1;
+ while (my $f = eval { $heap->{'twitter'}->followers({'cursor' =>
$cursor}) }) {
+ $cursor = $f->{'next_cursor'};
+ foreach my $user ($f->{'users'}) {
+ foreach my $u (@{$user}) {
+ push(@followers, $u);
+ }
+ }
+ last if $cursor == 0;
}
#alert this error, but don't end 'em - if ($page == 1 && $heap->{'twitter'}->http_code >= 400) { + if ($cursor == -1 && $heap->{'twitter'}->http_code >= 400) { $kernel->call($_[SESSION],'twitter_api_error','Unable to get followers list.'); }
Comment #1
Posted on Dec 4, 2009 by Massive RhinoAdding patch as attachment
Comment #2
Posted on Dec 4, 2009 by Massive Rhino(No comment was entered for this change.)
Attachments- p.diff 1.67KB
Comment #3
Posted on Dec 5, 2009 by Swift HippoThanks for noticing this issue and creating a patch, olatho.
Although, I'm getting the following;
gareth@sc1:~/.tircd$ patch < p.diff patching file tircd.pl Hunk #1 FAILED at 947. 1 out of 1 hunk FAILED -- saving rejects to file tircd.pl.rej
I've never applied a patch before, but it looks like I'm doing it correctly?
Any help would be appreciated.
Comment #4
Posted on Dec 5, 2009 by Massive RhinoI should have mentioned that my version of tircd.pl is from CVS here, not the 0.7-version that can be directly downloaded. You can also have a look at phinzes version in github: http://github.com/phinze/tircd He has added a few of the patches from these issues, but not this one (yet).
Comment #5
Posted on Dec 6, 2009 by Quick RabbitOlatho, thanks for the patch!
I too tried patching the 0.7 release and the "current" version from CVS. Neither works with "patch" directly, giving the error from moshdj2uk.
I then tried patching the files by hand, giving me this error when running the patched CVS version:
Global symbol "$page" requires explicit package name at tircd.pl line 956. Execution of tircd.pl aborted due to compilation errors.
Could you please specify the exact version you are patching? And would you like to share your tircd.pl with us? :)
A shame this awesome project seems abandoned. Someone should fork it. Although phinzes version in github was last touched in August, too.
Comment #6
Posted on Dec 6, 2009 by Massive RhinoI have added several patches to tirc.pl so this patch might not apply cleanly. But you should be able to find the code that I have changed here quite easily - somewhere around lines 940-950, and apply the changes manually.
Just search for "get list of friends" or something.
From the error "global symbol $page..." it seems like you still have references to this variable somewhere (on line 956). I have remove all references to this variable, and added the variable $cursor instead.
I had hoped tha phinze would keep updating his version in github, unfortunately I don't feel comfortable enough hacking perl to do a full fork myself.
Comment #7
Posted on Dec 6, 2009 by Quick RabbitAs I said, I already patched the current CVS version by hand. The result is attached.
Indeed the "$page" error was by fault, but now it's:
Unknown argument cursor passed, discarding. at ./tircd.pl line 945 Not a HASH reference at ./tircd.pl line 946.
Wouldn't you like to attach your tircd.pl for us to use? :)
Thanks again
- tircd.pl 41.77KB
Comment #8
Posted on Dec 6, 2009 by Massive RhinoHere is my tircd.pl
This is working fine for me atm. No problems with utf8, searches, friends and followers or other issues.
- tircd.pl 41.77KB
Comment #9
Posted on Dec 6, 2009 by Quick RabbitThanks. There's not much difference in our files, so I still get the same two errors.
I could solve "Unknown argument cursor passed" by replacing "cursor" with "page" again.
This seems to be a Net::Twitter issue. Let me guess: you're on v3 of Net::Twitter already? I'm still on 2.10.
"Not a HASH reference at tircd.pl line 949." remains though. That's this line: "$page = $f->{'next_page'};"
This is seems to be a Perl issue. I really am not a Perl guy, would you know a fix for this error?
Comment #10
Posted on Dec 6, 2009 by Massive RhinoYou can't just replace all references to "cursor" with "page". $f->{'next_cursor'} is retrieved from Twitter, so it needs to stay that way.
But you are right, I am on Net::Twitter v3.10001 so this might be your problem.
If you are root on the server, you can try to run "cpan Net::Twitter" from a shell to upgrade it (and its dependencies).
Comment #11
Posted on Dec 6, 2009 by Quick RabbitYup, installed Net::Twitter v3.10001 and it works.
Was there some kind of Twitter API change only incorporated in the newer Net::Twitter?
Thanks again!
Comment #12
Posted on Dec 6, 2009 by Massive RhinoTwitter changes its api in mysterious ways all the time it seems. =;-) - See issue 60 as well for another example (which is also fixed in my version of tircd.pl) I'll try to fix them as I find out about them, and maybe add updated versions of my tircd.pl to the issues here along the way. Have sent an email to crnelson asking if he has any plans on updating the official version as well.
Comment #13
Posted on Dec 6, 2009 by Quick RabbitCool, maybe ask paul.t.hinze too, if he would be interested in maintaining a fork when crnelson doesn't?
Comment #14
Posted on Jan 12, 2010 by Grumpy OxI'm seeing a similar issue in tircd 0.7, using Net::Twitter 2.10, with only a small number of friends and followers (much fewer than 100). I immediately get the "API limit" error and see no friends in #twitter.
Comment #15
Posted on Feb 11, 2010 by Happy Elephantim getting Unable to get friends list. (400 from Twitter API). as soon as i log into the server. no friends list at all.. i can post update to my twitter account tho.
Comment #16
Posted on Mar 1, 2010 by Happy Pandajaswentker, this issue is fixed in the new code. Unfortunately that code was only available in the git repository shared by a few of us until now.
Grab the .10 release on the main page and make sure you're version of Net::Twitter::Lite is up to date.
Status: Fixed
Labels:
Type-Defect
Priority-Medium