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
버전 4.13부터 폐지됨: The Twitter API v1.1 streaming statuses/filter endpoint that
AsyncStream
uses has a formal deprecation date of March 9, 2023.참고
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
.버전 4.0에 추가.
버전 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- 매개변수
- session
API와의 연결에 사용될 Aiohttp 클라이언트 세션.
- task
스트림 실행 중인 작업.
- 형식
- filter(*, follow=None, track=None, locations=None, filter_level=None, languages=None, stall_warnings=False)
실시간으로 트윗을 필터링합니다.
버전 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.- 매개변수
follow (list[int | str] | None) – 스트림에 트윗(Status)들을 포함시킬 대상 사용자의 ID값 리스트. 자세한 정보는 다음 URL을 참고하시기 바랍니다. https://developer.twitter.com/en/docs/twitter-api/v1/tweets/filter-realtime/guides/basic-stream-parameters
track (list[str] | None) – 검색·추적할 키워드. 키워드 구문의 리스트꼴로 지정해야 합니다.자세한 정보는 다음 URL을 참고하시기 바랍니다. https://developer.twitter.com/en/docs/tweets/filter-realtime/guides/basic-stream-parameters
locations (list[float] | None) – 검색·추적할 위치를 지정하는 경계 상자(Bounding box)의 집합.자세한 정보는 다음 URL을 참고하시기 바랍니다. https://developer.twitter.com/en/docs/tweets/filter-realtime/guides/basic-stream-parameters for more information.
filter_level (str | None) – 이 매개변수를 none, low 또는 medium 중 하나로 설정하면 스트림에 포함해야 하는 트윗 속성 중 filter_level 속성의 최솟값을 정합니다. 기본값은 none이며, 이는 모든 사용 가능한 트윗을 스트림에 포함합니다. 스트림의 트윗을 엔드유저(예: 프레젠테이션, 컨퍼런스의 대시보드 또는 라이브 피드)에게 트윗 스트림을 표시해야 할 때는, 이 값을 medium으로 설정하는 것을 권장합니다.
languages (list[str] | None) – 이 매개변수를 BCP 47 언어 식별자꼴로 표현되는, 쉼표(,)로 구분된 리스트로 설정하면(단, 트위터의 고급 검색 페이지에 있는 언어에 한함) 지정한 언어로 작성된 트윗만 반환합니다. 예로, language=ko 로 설정하면 한국어로 작성된 트윗만 스트림에 포함됩니다.
stall_warnings (bool | None) – 지연 경고(Stall warnings)를 전달할지의 여부.자세한 정보는 다음 URL을 참고하시기 바랍니다. https://developer.twitter.com/en/docs/tweets/filter-realtime/guides/basic-stream-parameters for more information.
- 예외 발생
TweepyException – 위치 좌표 수가 4의 배수가 아닌 경우
- 반환값
스트림 실행 중인 작업.
- 반환 형식
참조
- async on_data(raw_data)
코루틴 함수임(This function is a coroutine.)
스트림에서 원본 데이터(Raw data)가 수신되면 호출됩니다. 이 메서드는 메세지 유형에 따라 다른 메서드로 데이터를 전달합니다.
- 매개변수
raw_data (JSON) – 스트림으로부터의 원본 데이터(Raw data)
참조
- async on_status(status)
코루틴 함수임(This function is a coroutine.)
트윗(Status)을 받아오면 호출됨.
- 매개변수
status (Status) – 받아온 트윗(Status)
- 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_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) – 트위터로부터의 응답