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
Niezalecane od wersji 4.13: The Twitter API v1.1 streaming statuses/filter endpoint that
AsyncStream
uses has a formal deprecation date of March 9, 2023.Informacja
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 withAsyncStreamingClient
.Nowe w wersji 4.0.
Zmienione w wersji 4.13: Removed
sample
,on_delete
,on_scrub_geo
,on_status_withheld
, andon_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- Parametry
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
- task
The task running the stream
- Type
- filter(*, follow=None, track=None, locations=None, filter_level=None, languages=None, stall_warnings=False)
Filter realtime Tweets
Niezalecane od wersji 4.10: The delivery of compliance messages through the Twitter API v1.1 endpoint this method uses has been deprecated, and they will stop being delivered beginning October 29, 2022. Twitter API v2 can be used instead with
AsyncStreamingClient.filter()
and/orAsyncClient
batch compliance methods.- Parametry
follow (list[int | str] | None) – A list of user IDs, indicating the users to return statuses for in the stream. See https://developer.twitter.com/en/docs/twitter-api/v1/tweets/filter-realtime/guides/basic-stream-parameters for more information.
track (list[str] | None) – Keywords to track. Phrases of keywords are specified by a list. See https://developer.twitter.com/en/docs/tweets/filter-realtime/guides/basic-stream-parameters for more information.
locations (list[float] | None) – Specifies a set of bounding boxes to track. See https://developer.twitter.com/en/docs/tweets/filter-realtime/guides/basic-stream-parameters for more information.
Setting this parameter to one of none, low, or medium will set the minimum value of the filter_level Tweet attribute required to be included in the stream. The default value is none, which includes all available Tweets.
When displaying a stream of Tweets to end users (dashboards or live feeds at a presentation or conference, for example) it is suggested that you set this value to medium.
languages (list[str] | None) – Setting this parameter to a comma-separated list of BCP 47 language identifiers corresponding to any of the languages listed on Twitter’s advanced search page will only return Tweets that have been detected as being written in the specified languages. For example, connecting with language=en will only stream Tweets detected to be in the English language.
stall_warnings (bool | None) – Specifies whether stall warnings should be delivered. See https://developer.twitter.com/en/docs/tweets/filter-realtime/guides/basic-stream-parameters for more information.
- Wyrzuca
TweepyException – When the stream is already connected or when the number of location coordinates is not a multiple of 4
- Zwraca
The task running the stream
- Typ zwracany
References
- 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.
- Parametry
raw_data (JSON) – The raw data from the stream
References
- async on_status(status)
This function is a coroutine.
This is called when a status is received.
- Parametry
status (Status) – The Status received
- async on_disconnect_message(message)
This function is a coroutine.
This is called when a disconnect message is received.
- Parametry
message (JSON) – The disconnect message
- async on_limit(track)
This function is a coroutine.
This is called when a limit notice is received.
- Parametry
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.
- Parametry
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.
- Parametry
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.
- Parametry
exception (Exception) – The unhandled exception