tweepy.asynchronous.AsyncStream
— Asynchronous Stream Reference¶
- class tweepy.asynchronous.AsyncStream(consumer_key, consumer_secret, access_token, access_token_secret, *, max_retries=inf, proxy=None)¶
Stream realtime Tweets asynchronously
버전 4.0에 추가.
- 매개변수
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 (Optional[int]) – Number of times to attempt to (re)connect the stream.
proxy (Optional[str]) – Proxy URL
- session¶
Aiohttp client session used to connect to the API
- Type
Optional[aiohttp.ClientSession]
- task¶
The task running the stream
- Type
Optional[asyncio.Task]
- filter(*, follow=None, track=None, locations=None, filter_level=None, languages=None, stall_warnings=False)¶
Filter realtime Tweets
- 매개변수
follow (Optional[List[Union[int, str]]]) – 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 (Optional[List[str]]) – 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 (Optional[List[float]]) – 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.
filter_level (Optional[str]) –
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 (Optional[List[str]]) – 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 (Optional[bool]) – Specifies whether stall warnings should be delivered. See https://developer.twitter.com/en/docs/tweets/filter-realtime/guides/basic-stream-parameters for more information.
- 예외 발생
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
- 반환 형식
참조
- sample(*, languages=None, stall_warnings=False)¶
Sample realtime Tweets
- 매개변수
languages (Optional[List[str]]) – 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 (Optional[bool]) – Specifies whether stall warnings should be delivered. See https://developer.twitter.com/en/docs/tweets/filter-realtime/guides/basic-stream-parameters for more information.
- 예외 발생
TweepyException – When the stream is already connected
- 반환값
The task running the stream
- 반환 형식
참조
- 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
- 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
참조
- async on_status(status)¶
This function is a coroutine.
This is called when a status is received.
- 매개변수
status (Status) – The Status received
- async on_delete(status_id, user_id)¶
This function is a coroutine.
This is called when a status deletion notice is 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_scrub_geo(notice)¶
This function is a coroutine.
This is called when a location deletion notice is received.
- 매개변수
notice (JSON) – The location deletion notice
- async on_status_withheld(notice)¶
This function is a coroutine.
This is called when a status withheld content notice is received.
- 매개변수
notice (JSON) – The status withheld content notice