nltk.twitter.Streamer

class nltk.twitter.Streamer[source]

Bases: TwythonStreamer

Retrieve data from the Twitter Streaming API.

The streaming API requires OAuth 1.0 authentication.

__init__(app_key, app_secret, oauth_token, oauth_token_secret)[source]

Streaming class for a friendly streaming user experience Authentication IS required to use the Twitter Streaming API

Parameters
  • app_key – (required) Your applications key

  • app_secret – (required) Your applications secret key

  • oauth_token – (required) Used with oauth_token_secret to make authenticated calls

  • oauth_token_secret – (required) Used with oauth_token to make authenticated calls

  • timeout – (optional) How long (in secs) the streamer should wait for a response from Twitter Streaming API

  • retry_count – (optional) Number of times the API call should be retired

  • retry_in – (optional) Amount of time (in secs) the previous API call should be tried again

  • client_args – (optional) Accepts some requests Session parameters and some requests Request parameters. See http://docs.python-requests.org/en/latest/api/#sessionapi and requests section below it for details. [ex. headers, proxies, verify(SSL verification)]

  • handlers – (optional) Array of message types for which corresponding handlers will be called

  • chunk_size – (optional) Define the buffer size before data is actually returned from the Streaming API. Default: 1

register(handler)[source]

Register a method for handling Tweets.

Parameters

handler (TweetHandlerI) – method for viewing

on_success(data)[source]
Parameters

data – response from Twitter API

on_error(status_code, data)[source]
Parameters
  • status_code – The status code returned by the Twitter API

  • data – The response from Twitter API

sample()[source]

Wrapper for ‘statuses / sample’ API call

filter(track='', follow='', lang='en')[source]

Wrapper for ‘statuses / filter’ API call

disconnect()[source]

Used to disconnect the streaming client manually

on_timeout()[source]

Called when the request has timed out