物理の駅 Physics station by 現役研究者

テクノロジーは共有されてこそ栄える

Python tweepy twitterの標準検索APIの仕様 (日本語訳)

https://docs.tweepy.org/en/latest/api.html#tweepy.API.search_tweets

API.search_tweets(q, *, geocode, lang, locale, result_type, count, until, since_id, max_id, include_entities)

Returns a collection of relevant Tweets matching a specified query.
指定されたクエリ(q)に一致する関連ツイートのコレクションを戻します

注: クエリには色んな指定が可能

  • exclude:retweets リツイートを除く (オリジナルツイートを検索したい場合は付ける -filter:retweet と同じ)
  • until:2022-10-25_00:30:00_JST 日本時間で指定の時間までのツイート
  • since:2022-10-25_00:00:00_JST 日本時間で指定の時間よりあとのツイート
  • -ワード ワードを除く
  • -#ワード #ワードを除く

Please note that Twitter’s search service and, by extension, the Search API is not meant to be an exhaustive source of Tweets. Not all Tweets will be indexed or made available via the search interface.
Twitterの検索サービス、さらにSearch APIは、Tweetを完全な形で提供しているわけではありません。全てのTweetがインデックスに登録され、検索インターフェースから利用できるわけではありません。

Note

Twitter’s standard search API only “searches against a sampling of recent Tweets published in the past 7 days.”
Twitterの標準検索APIは「過去7日間に公開された最近のツイートのサンプルに対して検索」のみを行います。

If you’re specifying an ID range beyond the past 7 days or there are no results from the past 7 days, then no results will be returned.
過去7日間を超えるID範囲を指定している場合、または過去7日間の結果がない場合、結果は返されません。

See Twitter’s documentation on the standard search API for more information.
詳細は、標準検索APIに関するTwitterドキュメントを参照してください。

Note

In API v1.1, the response format of the Search API has been improved to return Tweet objects more similar to the objects you’ll find across the REST API and platform. However, perspectival attributes (fields that pertain to the perspective of the authenticating user) are not currently supported on this endpoint. 12

Changed in version 4.0: Renamed from API.search

Parameters q – The search query string of 500 characters maximum, including operators. Queries may additionally be limited by complexity.
演算子を含めて最大 500 文字の検索クエリ文字列。クエリは、複雑さによってさらに制限される場合があります。

geocode – Returns tweets by users located within a given radius of the given latitude/longitude. The location is preferentially taking from the Geotagging API, but will fall back to their Twitter profile. The parameter value is specified by “latitude,longitude,radius”, where radius units must be specified as either “mi” (miles) or “km” (kilometers). Note that you cannot use the near operator via the API to geocode arbitrary locations; however you can use this geocode parameter to search near geocodes directly. A maximum of 1,000 distinct “sub-regions” will be considered when using the radius modifier.
指定された緯度/経度の指定された半径内にいるユーザーによるツイートを返します。場所は Geotagging API から優先的に取得されますが、Twitter プロファイルにフォールバックされます。パラメータ値は「latitude,longitude,radius」で指定します。半径の単位は「mi」(マイル)または「km」(キロメートル)で指定する必要があります。 API 経由で near 演算子を使用して任意の場所をジオコーディングすることはできないことに注意してください。ただし、このジオコード パラメーターを使用して、近くのジオコードを直接検索できます。 radius 修飾子を使用する場合、最大 1,000 の個別の「サブ領域」が考慮されます。

lang – Restricts tweets to the given language, given by an ISO 639-1 code. Language detection is best-effort.
ツイートを ISO 639-1 コードで指定された言語に制限します。言語検出はベスト エフォートです。

locale – Specify the language of the query you are sending (only ja is currently effective). This is intended for language-specific consumers and the default should work in the majority of cases.
送信するクエリの言語を指定します (現在有効なのは ja のみです)。これは言語固有のコンシューマーを対象としており、ほとんどの場合、デフォルトで機能するはずです。

result_type –

Specifies what type of search results you would prefer to receive. The current default is “mixed.” Valid values include:
受け取りたい検索結果のタイプを指定します。現在のデフォルトは「mixed」です。有効な値は次のとおりです。

  • mixed : include both popular and real time results in the response
    一般的な結果とリアルタイムの結果の両方を応答に含めます
  • recent : return only the most recent results in the response
    レスポンスで最新の結果のみを返します
  • popular : return only the most popular results in the response
    応答で最も人気のある結果のみを返します

count – The number of results to try and retrieve per page.
ページごとに試行して取得する結果の数

注:最大100。それ以上を指定しても100個しか返ってこない

until – Returns tweets created before the given date. Date should be formatted as YYYY-MM-DD. Keep in mind that the search index has a 7-day limit. In other words, no tweets will be found for a date older than one week.
指定された日付より前に作成されたツイートを返します。日付は YYYY-MM-DD の形式にする必要があります。検索インデックスには 7 日間の制限があることに注意してください。つまり、1 週間以上前の日付のツイートは見つかりません。

since_id – Returns only statuses with an ID greater than (that is, more recent than) the specified ID. There are limits to the number of Tweets which can be accessed through the API. If the limit of Tweets has occurred since the since_id, the since_id will be forced to the oldest ID available.
指定された ID より大きい (つまり、新しい) ID を持つステータスのみを返します。 API 経由でアクセスできるツイートの数には制限があります。 since_id 以降にツイート数の制限が発生した場合、since_id は使用可能な最も古い ID に強制されます。

注: since_idよりも大きい(等しいのは含まない)(つまり新しい)Tweetを返す。

max_id – Returns only statuses with an ID less than (that is, older than) or equal to the specified ID.
指定された ID より小さい (つまり、古い) ID を持つステータスのみを返します。

注: 実際は、max_idに等しいかそれより小さい(つまり古い)Tweetを返す。

include_entities – The entities node will not be included when set to false. Defaults to true.
false に設定すると、エンティティ ノードは含まれません。デフォルトは true です。

注: entitiesとは、hashtags'、 'symbols'、'user_mentions'、'urls' の4つの情報

Returns

Return type: SearchResults

References

https://developer.twitter.com/en/docs/twitter-api/v1/tweets/search/api-reference/get-search-tweets