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/sample and v1.1 statuses/filter, the Twitter API v1.1 endpoints that AsyncStream uses. Twitter API v2 can be used instead with AsyncStreamingClient.

버전 4.0에 추가.

매개변수
  • consumer_key (str) – 트위터 API Consumer Key값

  • consumer_secret (str) – 트위터 API Consumer Secret값

  • access_token (str) – Twitter API 액세스 토큰

  • access_token_secret (str) – Twitter API 액세스 토큰 Secret값

  • max_retries (int | None) – 스트림에 (재)연결 시도할 횟수.

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

session

API와의 연결에 사용될 Aiohttp 클라이언트 세션.

형식

aiohttp.ClientSession | None

task

스트림 실행 중인 작업.

형식

asyncio.Task | None

user_agent

API 연결에 사용되는 사용자 에이전트(User agent).

형식

str

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

실시간으로 트윗을 필터링합니다.

매개변수
예외 발생

TweepyException – 위치 좌표 수가 4의 배수가 아닌 경우

반환값

스트림 실행 중인 작업.

반환 형식

asyncio.Task

참조

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

sample(*, languages=None, stall_warnings=False)

실시간으로 트윗을 샘플링합니다.

매개변수
예외 발생

TweepyException – 스트림이 이미 연결되어있는 경우

반환값

스트림 실행 중인 작업.

반환 형식

asyncio.Task

참조

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

async on_data(raw_data)

코루틴 함수임(This function is a coroutine.)

스트림에서 원본 데이터(Raw data)가 수신되면 호출됩니다. 이 메서드는 메세지 유형에 따라 다른 메서드로 데이터를 전달합니다.

매개변수

raw_data (JSON) – 스트림으로부터의 원본 데이터(Raw data)

참조

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.)

트윗(Status)을 받아오면 호출됨.

매개변수

status (Status) – 받아온 트윗(Status)

async on_delete(status_id, user_id)

코루틴 함수임(This function is a coroutine.)

트윗(Status) 삭제를 전달받으면 호출됨.

매개변수
  • status_id (int) – 삭제된 트윗의 ID.

  • user_id (int) – 트윗 작성자의 ID.

async on_disconnect_message(message)

코루틴 함수임(This function is a coroutine.)

연결 종료 메세지를 받으면 호출됨.

매개변수

message (JSON) – 연결 종료 메세지

async on_limit(track)

코루틴 함수임(This function is a coroutine.)

API 호출 제한을 전달받으면 호출됨.

매개변수

track (int) – 연결 수립 후 전달되지 않은 트윗의 총 개수

async on_scrub_geo(notice)

코루틴 함수임(This function is a coroutine.)

특정 위치의 삭제를 전달받으면 호출됨.

매개변수

notice (JSON) – 특정 위치 삭제 통지

async on_status_withheld(notice)

코루틴 함수임(This function is a coroutine.)

트윗(Status) 내용 보류를 전달받으면 호출됨.

매개변수

notice (JSON) – 내용 보류 통지 대상 트윗(Status)

async on_user_withheld(notice)

코루틴 함수임(This function is a coroutine.)

사용자가 보류된 내용(의 통지)를 전달받았을때 호출됨.

매개변수

notice (JSON) – 내용 보류 통지를 받은 사용자

async on_warning(notice)

코루틴 함수임(This function is a coroutine.)

지연 경고(Stall warnings)를 전달받으면 호출됨.

매개변수

warning (JSON) – 지연 경고(Stall warnings)

disconnect()

스트림과의 연결을 종료함

async on_closed(resp)

코루틴 함수임(This function is a coroutine.)

트위터에 의해 스트림이 닫힐 경우 호출됨.

매개변수

response (aiohttp.ClientResponse) – 트위터로부터의 응답

async on_connect()

코루틴 함수임(This function is a coroutine.)

스트리밍 API에 성공적으로 연결되면 호출됨.

async on_connection_error()

코루틴 함수임(This function is a coroutine.)

스트림 연결 오류 및 시간 초과시 호출됨.

async on_disconnect()

코루틴 함수임(This function is a coroutine.)

스트림 연결이 종료되면 호출됨.

async on_exception(exception)

코루틴 함수임(This function is a coroutine.)

처리되지 않은 예외가 발생하면 호출됨.

매개변수

exception (Exception) – 처리되지 않은 예외

async on_keep_alive()

코루틴 함수임(This function is a coroutine.)

keep-alive 신호를 받을 때 호출됨.

async on_request_error(status_code)

코루틴 함수임(This function is a coroutine.)

HTTP 200이 아닌 상태 코드가 반환되면 호출됨.

매개변수

status_code (int) – 발생한 HTTP 상태 코드