I’m trying to use the AnyEvent::Twitter::Stream module and I want to reference a file that lists the Twitter uids I want to follow. I can put the uids in the code itself and it works as follows:
my $done = AnyEvent->condvar;
my $nt_filter = AnyEvent::Twitter::Stream->new(
username => $cf{account},
password => $cf{password},
method => 'filter',
follow => '15855509,14760150,18598536',
on_tweet => sub {
#some code.....
},
on_error => sub {
my $error = shift;
debug "ERROR: $error";
},
timeout => 45,
);
$done->recv;
But when I try to do the same using a file as such:
my $done = AnyEvent->condvar;
my $nt_filter = AnyEvent::Twitter::Stream->new(
open UID_FILE, "/tmp/uids" or die $!;
my @uid_line = <UID_FILE>;
username => $cf{account},
password => $cf{password},
method => 'filter',
follow => @uid_file,
on_tweet => sub {
#some code....
},
on_error => sub {
my $error = shift;
debug "ERROR: $error";
},
timeout => 45,
);
$done->recv;
it fails. The uids file has the following contents:
'15855509,14760150,18598536'
I’m getting a 406 error from Twitter, suggesting the format is not correct. I’m guessing the quotes are not correct somehow?
The
AnyEvent::Twitter::Streammodule subclassesAnyEventand you don’t need to access the base module at all. All the functionality is provided by thenewmethod and the callbacks that you specify there, and you shouldn’t callAnyEvent->condvaror$done->recv.The
opencall and assignment to@uid_linedon’t belong inside the call toAnyEvent::Twitter::Stream->new.Furthermore the variable you are using to supply the value for the
followparameter is@uid_fileinstead of@uid_line.You must
use strict;anduse warnings;at the start of your programs, especially if you are asking for help with them. This will trap simple mistakes like this that you could otherwise overlook.You can’t in general use an array to supply a single scalar value. In this instance it may be OK as long as the file has only a single line (so there is only one element in the array) but there is a lot that could go wrong.
In addition you are passing single-quotes in the value that don’t belong there: they appear in the code only to mark the start and end of the Perl string.
I suggest you read all decimal strings from your file like this
(Note that these lines belong before the call to
AnyEvent::Twitter::Stream->new)Then you can supply the
followparameter by writingI hope this is clear. Please ask again if you need further help.
Edit
These changes incorporated into your code should look like this, but it is incomplete and I cannot guarantee that it will work properly.