Skip to content

Instantly share code, notes, and snippets.

@chris-x86-64
Created June 23, 2013 07:24
Show Gist options
  • Save chris-x86-64/5844148 to your computer and use it in GitHub Desktop.
Save chris-x86-64/5844148 to your computer and use it in GitHub Desktop.
Very simple example of AnyEvent::Twitter::Stream
#!/usr/bin/perl
use strict;
use warnings;
use feature 'say';
use Encode;
use utf8;
use Data::Dumper;
use AnyEvent::Twitter::Stream;
use YAML::Syck;
my $conf = YAML::Syck::LoadFile('config.yml');
my $oauth = $conf->{oauth};
my $done = AE::cv;
my $stream = AnyEvent::Twitter::Stream->new(
token => $oauth->{access_token},
token_secret => $oauth->{access_token_secret},
consumer_key => $oauth->{consumer_key},
consumer_secret => $oauth->{consumer_secret},
ANYEVENT_TWITTER_STREAM_SSL => 1,
method => "userstream",
on_connect => sub {
},
on_tweet => sub {
my $tweet = shift;
return unless ($tweet->{id});
print Dumper($tweet);
},
on_event => sub {
my $event = shift;
print Dumper($event);
},
on_error => sub {
my $error = shift;
warn "Error: $error\n";
$done->send;
},
on_eof => sub {
$done->send;
},
);
$done->recv;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment