[PR]

AsyncStream

class tweepy.asynchronous.AsyncStream(consumer_key, consumer_secret, access_token, access_token_secret, *, max_retries=inf, proxy=None)

Stream realtime Tweets asynchronously with Twitter API v1.1

注釈

New Twitter Developer Apps created on or after April 29, 2022 will not be able to gain access to v1.1 statuses/filter, the Twitter API v1.1 endpoint that AsyncStream uses. Twitter API v2 can be used instead with AsyncStreamingClient.

バージョン 4.0 で追加.

バージョン 4.13 で変更: Removed sample, on_delete, on_scrub_geo, on_status_withheld, and on_user_withheld methods, as the Twitter API v1.1 statuses/sample endpoint and compliance messages on the Twitter API v1.1 statuses/filter endpoint have been retired

パラメータ:
  • consumer_key (str) -- Twitter API Consumer Key

  • consumer_secret (str) -- Twitter API Consumer Secret

  • access_token (str) -- Twitter API Access Token

  • access_token_secret (str) -- Twitter API Access Token Secret

  • max_retries (int | None) -- Number of times to attempt to (re)connect the stream.

  • proxy (str | None) -- URL of the proxy to use when connecting to the stream

session

Aiohttp client session used to connect to the API

Type:

aiohttp.ClientSession | None

task

The task running the stream

Type:

asyncio.Task | None

user_agent

User agent used when connecting to the API

Type:

str

filter(*, follow=None, track=None, locations=None, filter_level=None, languages=None, stall_warnings=False)

Filter realtime Tweets

パラメータ:
例外:

TweepyException -- When the stream is already connected or when the number of location coordinates is not a multiple of 4

戻り値:

The task running the stream

戻り値の型:

asyncio.Task

参照

https://developer.twitter.com/en/docs/twitter-api/v1/tweets/filter-realtime/api-reference/post-statuses-filter

async on_data(raw_data)

This function is a coroutine.

This is called when raw data is received from the stream. This method handles sending the data to other methods, depending on the message type.

パラメータ:

raw_data (JSON) -- The raw data from the stream

参照

https://developer.twitter.com/en/docs/twitter-api/v1/tweets/filter-realtime/guides/streaming-message-types

async on_status(status)

This function is a coroutine.

This is called when a status is received.

パラメータ:

status (Status) -- The Status received

async on_disconnect_message(message)

This function is a coroutine.

This is called when a disconnect message is received.

パラメータ:

message (JSON) -- The disconnect message

async on_limit(track)

This function is a coroutine.

This is called when a limit notice is received.

パラメータ:

track (int) -- Total count of the number of undelivered Tweets since the connection was opened

async on_warning(notice)

This function is a coroutine.

This is called when a stall warning message is received.

パラメータ:

warning (JSON) -- The stall warning

disconnect()

Disconnect the stream

async on_closed(resp)

This function is a coroutine.

This is called when the stream has been closed by Twitter.

パラメータ:

response (aiohttp.ClientResponse) -- The response from Twitter

async on_connect()

This function is a coroutine.

This is called after successfully connecting to the streaming API.

async on_connection_error()

This function is a coroutine.

This is called when the stream connection errors or times out.

async on_disconnect()

This function is a coroutine.

This is called when the stream has disconnected.

async on_exception(exception)

This function is a coroutine.

This is called when an unhandled exception occurs.

パラメータ:

exception (Exception) -- The unhandled exception

async on_keep_alive()

This function is a coroutine.

This is called when a keep-alive signal is received.

async on_request_error(status_code)

This function is a coroutine.

This is called when a non-200 HTTP status code is encountered.

パラメータ:

status_code (int) -- The HTTP status code encountered