Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

AnyEvent based Twitter stream consumer

Octocat-spinner-32 eg get Compression working (again) in a fashion closer to the existing code November 05, 2012
Octocat-spinner-32 lib Update documentation. #16 July 03, 2013
Octocat-spinner-32 t fix test endpoint March 10, 2013
Octocat-spinner-32 xt added stop words January 19, 2011
Octocat-spinner-32 .gitignore update May 13, 2013
Octocat-spinner-32 .travis.yml enable Travis May 20, 2013
Octocat-spinner-32 Build.PL 0.26 June 10, 2013
Octocat-spinner-32 Changes 0.26 June 10, 2013
Octocat-spinner-32 META.json 0.26 June 10, 2013
Octocat-spinner-32 README.md Milla May 13, 2013
Octocat-spinner-32 cpanfile Fix deps June 10, 2013
Octocat-spinner-32 dist.ini Milla May 13, 2013
README.md

NAME

AnyEvent::Twitter::Stream - Receive Twitter streaming API in an event loop

SYNOPSIS

use AnyEvent::Twitter::Stream;

# receive updates from @following_ids
my $listener = AnyEvent::Twitter::Stream->new(
    username => $user,
    password => $password,
    method   => "filter",  # "firehose" for everything, "sample" for sample timeline
    follow   => join(",", @following_ids),
    on_tweet => sub {
        my $tweet = shift;
        warn "$tweet->{user}{screen_name}: $tweet->{text}\n";
    },
    on_keepalive => sub {
        warn "ping\n";
    },
    on_delete => sub {
        my ($tweet_id, $user_id) = @_; # callback executed when twitter send a delete notification
        ...
    },
    timeout => 45,
);

# track keywords
my $guard = AnyEvent::Twitter::Stream->new(
    username => $user,
    password => $password,
    method   => "filter",
    track    => "Perl,Test,Music",
    on_tweet => sub { },
);

# to use OAuth authentication
my $listener = AnyEvent::Twitter::Stream->new(
    consumer_key    => $consumer_key,
    consumer_secret => $consumer_secret,
    token           => $token,
    token_secret    => $token_secret,
    method          => "filter",
    track           => "...",
    on_tweet        => sub { ... },
);

DESCRIPTION

AnyEvent::Twitter::Stream is an AnyEvent user to receive Twitter streaming API, available at http://dev.twitter.com/pages/streaming_api and http://dev.twitter.com/pages/user_streams.

See "track.pl" in eg for more client code example.

METHODS

my $streamer = AnyEvent::Twitter::Stream->new(%args);

  • username password

    These arguments are used for basic authentication.

  • consumer_key consumer_secret token token_secret

    If you want to use the OAuth authentication mechanism, you need to set use arguments

  • consumer_key consumer_secret token token_secret

    If you want to use the OAuth authentication mechanism, you need to set these arguments

  • method

    The name of the method you want to use on the stream. Currently, anyone of :

    • firehose
    • sample
    • userstream

      To use this method, you need to use the OAuth mechanism.

    • filter

      With this method you can specify what you want to filter amongst track, follow and locations.

  • api_url

    Pass this to override the default URL for the API endpoint.

  • request_method

    Pass this to override the default HTTP request method.

  • timeout

    Set the timeout value.

  • on_connect

    Callback to execute when a stream is connected.

  • on_tweet

    Callback to execute when a new tweet is received.

  • on_error

  • on_eof
  • on_keepalive
  • on_delete

    Callback to execute when the stream send a delete notification.

  • on_friends

    Only with the usertream method. Callback to execute when the stream send a list of friends.

  • on_direct_message

    Only with the usertream method. Callback to execute when a direct message is received in the stream.

  • on_event

    Only with the userstream method. Callback to execute when the stream send an event notification (follow, ...).

  • additional agruments

    Any additional arguments are assumed to be parameters to the underlying API method and are passed to Twitter.

NOTES

To use the userstream method, Twitter recommend using the HTTPS protocol. For this, you need to set the ANYEVENT_TWITTER_STREAM_SSL environment variable, and install the Net::SSLeay module.

AUTHOR

Tatsuhiko Miyagawa miyagawa@bulknews.net

LICENSE

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

SEE ALSO

AnyEvent::Twitter, Net::Twitter::Stream

Something went wrong with that request. Please try again.