APIリファレンス

このページにはTweepyモジュールの基本的なドキュメントが含まれています。

tweepy.api — Twitter APIラッパー

class API([auth_handler=None][, host='api.twitter.com'][, search_host='search.twitter.com'][, cache=None][, api_root='/1'][, search_root=''][, retry_count=0][, retry_delay=0][, retry_errors=None][, timeout=60][, parser=ModelParser][, compression=False][, wait_on_rate_limit=False][, wait_on_rate_limit_notify=False][, proxy=None])

このクラスは、Twitterが提供するAPIのラッパーを提供します。このクラスで提供される関数を以下に示します。

パラメータ:
  • auth_handler – 認証ハンドラ
  • host – 一般的なAPIホスト
  • search_host – 検索APIホスト
  • cache – キャッシュバックエンド
  • api_root – 一般的なAPIパスのルート
  • search_root – 検索APIパスのルート
  • retry_count – エラーが発生したときに再試行するデフォルトの回数
  • retry_delay – 再試行の間に待機する秒数
  • retry_errors – 再試行するHTTPステータスコード
  • timeout – Twitterからの応答を待つ最大時間
  • parser – Twitterからの応答を解析するために使用するオブジェクト
  • compression – 要求にGZIP圧縮を使用するかどうか
  • wait_on_rate_limit – 利用制限が解除されるのを自動的に待つかどうか
  • wait_on_rate_limit_notify – Tweepyが利用制限が解除されるのを待っているときに通知を表示するかどうか
  • proxy – Twitterに接続するためのHTTPSプロキシのURL

Timelineメソッド

API.home_timeline([since_id][, max_id][, count][, page])

フォロワーとそのフォロワーの友人が投稿したretweetsを含む最新の20個のツイートを返します。これはWeb上の/timeline/homeに相当します。

パラメータ:
  • since_id – Returns only statuses with an ID greater than (that is, more recent than) the specified ID.
  • max_id – Returns only statuses with an ID less than (that is, older than) or equal to the specified ID.
  • count – Specifies the number of statuses to retrieve.
  • page – Specifies the page of results to retrieve. Note: there are pagination limits.
戻り値の型:

Status オブジェクトのリスト

API.statuses_lookup(id[, include_entities][, trim_user][, map])

id パラメータで指定された、リクエスト毎に最大100個のTweetオブジェクトを返します。

パラメータ:
  • id – 検索するツイートIDのリスト。最大100
  • include_entities – 返却されたツイートにエンティティ(https://dev.twitter.com/docs/entities)を含めるかどうか
  • trim_user – A boolean indicating if user IDs should be provided, instead of full user information. Defaults to False.
  • map – 完全なユーザー情報ではなく、ユーザーIDを提供するかどうかデフォルトはFalseです。
戻り値の型:

Status オブジェクトのリスト

API.user_timeline([id/user_id/screen_name][, since_id][, max_id][, count][, page])

フォロワーや指定されたユーザーから最新の20個のツイートを返します。idパラメータを使用して別のユーザーのタイムラインを取得することもできます。

パラメータ:
  • id – Specifies the ID or screen name of the user.
  • user_id – Specifies the ID of the user. Helpful for disambiguating when a valid user ID is also a valid screen name.
  • screen_name – Specifies the screen name of the user. Helpful for disambiguating when a valid screen name is also a user ID.
  • since_id – Returns only statuses with an ID greater than (that is, more recent than) the specified ID.
  • max_id – Returns only statuses with an ID less than (that is, older than) or equal to the specified ID.
  • count – Specifies the number of statuses to retrieve.
  • page – Specifies the page of results to retrieve. Note: there are pagination limits.
戻り値の型:

Status オブジェクトのリスト

API.retweets_of_me([since_id][, max_id][, count][, page])

他の人がリツイートしたフォロワーの最新の20のつぶやきを返します。

パラメータ:
  • since_id – Returns only statuses with an ID greater than (that is, more recent than) the specified ID.
  • max_id – Returns only statuses with an ID less than (that is, older than) or equal to the specified ID.
  • count – Specifies the number of statuses to retrieve.
  • page – Specifies the page of results to retrieve. Note: there are pagination limits.
戻り値の型:

Status オブジェクトのリスト

Status メソッド

API.get_status(id)

IDパラメータで指定された単一のステータスを返します。

パラメータ:id – The numerical ID of the status.
戻り値の型:Status object
API.update_status(status[, in_reply_to_status_id][, auto_populate_reply_metadata][, lat][, long][, source][, place_id])

認証されたユーザーのステータスを更新します。重複しているか長すぎるステータスは暗黙のうちに無視されます。

パラメータ:
  • status – statusテキストを更新します。
  • in_reply_to_status_id – 更新プログラムが応答する既存のステータスのID。
  • auto_populate_reply_metadata – ステータスメタデータに@mentionsを自動的に含めるかどうか。
  • lat – ツイートした場所の緯度。
  • long – ツイートした場所の経度。
  • source – Source of the update. Only supported by Identi.ca. Twitter ignores this parameter.
  • place_id – ユーザーのジオロケーションが有効になっている場合、ツイートにリストされている場所のTwitter ID。
戻り値の型:

Status object

API.update_with_media(filename[, status][, in_reply_to_status_id][, auto_populate_reply_metadata][, lat][, long][, source][, place_id][, file])

認証されたユーザーのステータスを更新します。重複しているか長すぎるステータスは暗黙のうちに無視されます。

パラメータ:
  • filename – The filename of the image to upload. This will automatically be opened unless file is specified
  • status – statusテキストを更新します。
  • in_reply_to_status_id – 更新プログラムが応答する既存のステータスのID。
  • auto_populate_reply_metadata – ステータスメタデータに@mentionsを自動的に含めるかどうか。
  • lat – ツイートした場所の緯度。
  • long – ツイートした場所の経度。
  • source – Source of the update. Only supported by Identi.ca. Twitter ignores this parameter.
  • place_id – ユーザーのジオロケーションが有効になっている場合、ツイートにリストされている場所のTwitter ID。
  • file – A file object, which will be used instead of opening filename. filename is still required, for MIME type detection and to use as a form field in the POST data
戻り値の型:

Status object

API.destroy_status(id)

idパラメータで指定されたstatusを削除します。削除するには作成者でなければなりません。

パラメータ:id – The numerical ID of the status.
戻り値の型:Status object
API.retweet(id)

リツイートします。リツイートするツイートのIDが必要です。

パラメータ:id – The numerical ID of the status.
戻り値の型:Status object
API.retweets(id[, count])

指定したツイートの最初から100までのリツイート数を返します。

パラメータ:
  • id – The numerical ID of the status.
  • count – Specifies the number of retweets to retrieve.
戻り値の型:

Status オブジェクトのリスト

User methods

API.get_user(id/user_id/screen_name)

Returns information about the specified user.

パラメータ:
  • id – Specifies the ID or screen name of the user.
  • user_id – Specifies the ID of the user. Helpful for disambiguating when a valid user ID is also a valid screen name.
  • screen_name – Specifies the screen name of the user. Helpful for disambiguating when a valid screen name is also a user ID.
戻り値の型:

User object

API.me()

認証したユーザーの情報を返します。

戻り値の型:User object
API.followers([id/screen_name/user_id][, cursor])

一度に100のフォロワーを返します。id/screen_nameで指定されたユーザがない場合、デフォルトでは認証したユーザになります。

パラメータ:
  • id – Specifies the ID or screen name of the user.
  • user_id – Specifies the ID of the user. Helpful for disambiguating when a valid user ID is also a valid screen name.
  • screen_name – Specifies the screen name of the user. Helpful for disambiguating when a valid screen name is also a user ID.
  • cursor – Breaks the results into pages. Provide a value of -1 to begin paging. Provide values as returned to in the response body’s next_cursor and previous_cursor attributes to page back and forth in the list.
戻り値の型:

list of User objects

API.search_users(q[, per_page][, page])

Twitter.comのFind Peopleボタンに似たユーザーの検索を実行します。このAPIを使用するとTwitter.comでの人物検索によって返されたのと同じ結果が返されます。このAPIから最初の1000件を検索することは可能です。

パラメータ:
  • q – The query to run against people search.
  • per_page – Specifies the number of statuses to retrieve. May not be greater than 20.
  • page – Specifies the page of results to retrieve. Note: there are pagination limits.
戻り値の型:

list of User objects

Direct Message Methods

API.direct_messages([since_id][, max_id][, count][, page][, full_text])

Returns direct messages sent to the authenticating user.

パラメータ:
  • since_id – Returns only statuses with an ID greater than (that is, more recent than) the specified ID.
  • max_id – Returns only statuses with an ID less than (that is, older than) or equal to the specified ID.
  • count – Specifies the number of statuses to retrieve.
  • page – Specifies the page of results to retrieve. Note: there are pagination limits.
  • full_text – A boolean indicating whether or not the full text of a message should be returned. If False the message text returned will be truncated to 140 chars. Defaults to False.
戻り値の型:

list of DirectMessage objects

API.get_direct_message([id][, full_text])

Returns a specific direct message.

パラメータ:
  • id|id|
  • full_text – A boolean indicating whether or not the full text of a message should be returned. If False the message text returned will be truncated to 140 chars. Defaults to False.
戻り値の型:

DirectMessage object

API.sent_direct_messages([since_id][, max_id][, count][, page][, full_text])

Returns direct messages sent by the authenticating user.

パラメータ:
  • since_id – Returns only statuses with an ID greater than (that is, more recent than) the specified ID.
  • max_id – Returns only statuses with an ID less than (that is, older than) or equal to the specified ID.
  • count – Specifies the number of statuses to retrieve.
  • page – Specifies the page of results to retrieve. Note: there are pagination limits.
  • full_text – A boolean indicating whether or not the full text of a message should be returned. If False the message text returned will be truncated to 140 chars. Defaults to False.
戻り値の型:

list of DirectMessage objects

API.send_direct_message(user/screen_name/user_id, text)

Sends a new direct message to the specified user from the authenticating user.

パラメータ:
  • user – The ID or screen name of the recipient user.
  • screen_name – screen name of the recipient user
  • user_id – user id of the recipient user
戻り値の型:

DirectMessage object

API.destroy_direct_message(id)

Destroy a direct message. Authenticating user must be the recipient of the direct message.

パラメータ:id – The ID of the direct message to destroy.
戻り値の型:DirectMessage object

Friendship Methods

API.create_friendship(id/screen_name/user_id[, follow])

Create a new friendship with the specified user (aka follow).

パラメータ:
  • id – Specifies the ID or screen name of the user.
  • screen_name – Specifies the screen name of the user. Helpful for disambiguating when a valid screen name is also a user ID.
  • user_id – Specifies the ID of the user. Helpful for disambiguating when a valid user ID is also a valid screen name.
  • follow – Enable notifications for the target user in addition to becoming friends.
戻り値の型:

User object

API.destroy_friendship(id/screen_name/user_id)

Destroy a friendship with the specified user (aka unfollow).

パラメータ:
  • id – Specifies the ID or screen name of the user.
  • screen_name – Specifies the screen name of the user. Helpful for disambiguating when a valid screen name is also a user ID.
  • user_id – Specifies the ID of the user. Helpful for disambiguating when a valid user ID is also a valid screen name.
戻り値の型:

User object

API.exists_friendship(user_a, user_b)

Checks if a friendship exists between two users. Will return True if user_a follows user_b, otherwise False.

パラメータ:
  • user_a – The ID or screen_name of the subject user.
  • user_b – The ID or screen_name of the user to test for following.
戻り値の型:

True/False

API.show_friendship(source_id/source_screen_name, target_id/target_screen_name)

Returns detailed information about the relationship between two users.

パラメータ:
  • source_id – The user_id of the subject user.
  • source_screen_name – The screen_name of the subject user.
  • target_id – The user_id of the target user.
  • target_screen_name – The screen_name of the target user.
戻り値の型:

Friendship object

API.friends_ids(id/screen_name/user_id[, cursor])

Returns an array containing the IDs of users being followed by the specified user.

パラメータ:
  • id – Specifies the ID or screen name of the user.
  • screen_name – Specifies the screen name of the user. Helpful for disambiguating when a valid screen name is also a user ID.
  • user_id – Specifies the ID of the user. Helpful for disambiguating when a valid user ID is also a valid screen name.
  • cursor – Breaks the results into pages. Provide a value of -1 to begin paging. Provide values as returned to in the response body’s next_cursor and previous_cursor attributes to page back and forth in the list.
戻り値の型:

list of Integers

API.followers_ids(id/screen_name/user_id)

Returns an array containing the IDs of users following the specified user.

パラメータ:
  • id – Specifies the ID or screen name of the user.
  • screen_name – Specifies the screen name of the user. Helpful for disambiguating when a valid screen name is also a user ID.
  • user_id – Specifies the ID of the user. Helpful for disambiguating when a valid user ID is also a valid screen name.
  • cursor – Breaks the results into pages. Provide a value of -1 to begin paging. Provide values as returned to in the response body’s next_cursor and previous_cursor attributes to page back and forth in the list.
戻り値の型:

list of Integers

Account Methods

API.verify_credentials()

Verify the supplied user credentials are valid.

戻り値の型:User object if credentials are valid, otherwise False
API.rate_limit_status()

Returns the remaining number of API requests available to the requesting user before the API limit is reached for the current hour. Calls to rate_limit_status do not count against the rate limit. If authentication credentials are provided, the rate limit status for the authenticating user is returned. Otherwise, the rate limit status for the requester’s IP address is returned.

戻り値の型:JSON object
API.set_delivery_device(device)

Sets which device Twitter delivers updates to for the authenticating user. Sending 「none」 as the device parameter will disable SMS updates.

パラメータ:device – Must be one of: sms, none
戻り値の型:User object
API.update_profile_colors([profile_background_color][, profile_text_color][, profile_link_color][, profile_sidebar_fill_color][, profile_sidebar_border_color])

Sets one or more hex values that control the color scheme of the authenticating user’s profile page on twitter.com.

パラメータ:
  • profile_background_color
  • profile_text_color
  • profile_link_color
  • profile_sidebar_fill_color
  • profile_sidebar_border_color
戻り値の型:

User object

API.update_profile_image(filename)

Update the authenticating user’s profile image. Valid formats: GIF, JPG, or PNG

パラメータ:filename – local path to image file to upload. Not a remote URL!
戻り値の型:User object
API.update_profile_background_image(filename)

Update authenticating user’s background image. Valid formats: GIF, JPG, or PNG

パラメータ:filename – local path to image file to upload. Not a remote URL!
戻り値の型:User object
API.update_profile([name][, url][, location][, description])

Sets values that users are able to set under the 「Account」 tab of their settings page.

パラメータ:
  • name – Maximum of 20 characters
  • url – Maximum of 100 characters. Will be prepended with 「http://」 if not present
  • location – Maximum of 30 characters
  • description – Maximum of 160 characters
戻り値の型:

User object

Favorite Methods

API.favorites([id][, page])

Returns the favorite statuses for the authenticating user or user specified by the ID parameter.

パラメータ:
  • id – The ID or screen name of the user to request favorites
  • page – Specifies the page of results to retrieve. Note: there are pagination limits.
戻り値の型:

Status オブジェクトのリスト

API.create_favorite(id)

Favorites the status specified in the ID parameter as the authenticating user.

パラメータ:id – The numerical ID of the status.
戻り値の型:Status object
API.destroy_favorite(id)

Un-favorites the status specified in the ID parameter as the authenticating user.

パラメータ:id – The numerical ID of the status.
戻り値の型:Status object

Block Methods

API.create_block(id/screen_name/user_id)

Blocks the user specified in the ID parameter as the authenticating user. Destroys a friendship to the blocked user if it exists.

パラメータ:
  • id – Specifies the ID or screen name of the user.
  • screen_name – Specifies the screen name of the user. Helpful for disambiguating when a valid screen name is also a user ID.
  • user_id – Specifies the ID of the user. Helpful for disambiguating when a valid user ID is also a valid screen name.
戻り値の型:

User object

API.destroy_block(id/screen_name/user_id)

Un-blocks the user specified in the ID parameter for the authenticating user.

パラメータ:
  • id – Specifies the ID or screen name of the user.
  • screen_name – Specifies the screen name of the user. Helpful for disambiguating when a valid screen name is also a user ID.
  • user_id – Specifies the ID of the user. Helpful for disambiguating when a valid user ID is also a valid screen name.
戻り値の型:

User object

API.blocks([page])

Returns an array of user objects that the authenticating user is blocking.

パラメータ:page – Specifies the page of results to retrieve. Note: there are pagination limits.
戻り値の型:list of User objects
API.blocks_ids()

Returns an array of numeric user ids the authenticating user is blocking.

戻り値の型:list of Integers

Spam Reporting Methods

API.report_spam([id/user_id/screen_name])

The user specified in the id is blocked by the authenticated user and reported as a spammer.

パラメータ:
  • id – Specifies the ID or screen name of the user.
  • screen_name – Specifies the screen name of the user. Helpful for disambiguating when a valid screen name is also a user ID.
  • user_id – Specifies the ID of the user. Helpful for disambiguating when a valid user ID is also a valid screen name.
戻り値の型:

User object

Saved Searches Methods

API.saved_searches()

Returns the authenticated user’s saved search queries.

戻り値の型:list of SavedSearch objects

Retrieve the data for a saved search owned by the authenticating user specified by the given id.

パラメータ:id – The id of the saved search to be retrieved.
戻り値の型:SavedSearch object

Creates a saved search for the authenticated user.

パラメータ:query – The query of the search the user would like to save.
戻り値の型:SavedSearch object

Destroys a saved search for the authenticated user. The search specified by id must be owned by the authenticating user.

パラメータ:id – The id of the saved search to be deleted.
戻り値の型:SavedSearch object

Help Methods

API.search(q[, lang][, locale][, rpp][, page][, since_id][, geocode][, show_user])

Returns tweets that match a specified query.

パラメータ:
  • q – the search query string
  • lang – Restricts tweets to the given language, given by an ISO 639-1 code.
  • locale – Specify the language of the query you are sending. This is intended for language-specific clients and the default should work in the majority of cases.
  • rpp – The number of tweets to return per page, up to a max of 100.
  • page – The page number (starting at 1) to return, up to a max of roughly 1500 results (based on rpp * page.
  • since_id – Returns only statuses with an ID greater than (that is, more recent than) the specified ID.
  • 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 「latitide,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.
  • show_user – When true, prepends 「<user>:」 to the beginning of the tweet. This is useful for readers that do not display Atom’s author field. The default is false.
戻り値の型:

list of SearchResult objects

List Methods

API.create_list(name[, mode][, description])

Creates a new list for the authenticated user. Accounts are limited to 20 lists.

パラメータ:
  • name – The name of the new list.
  • mode – Whether your list is public or private. Values can be public or private. Lists are public by default if no mode is specified.
  • description – The description of the list you are creating.
戻り値の型:

List object

API.destroy_list(slug)

Deletes the specified list. Must be owned by the authenticated user.

パラメータ:slug – the slug name or numerical ID of the list
戻り値の型:List object
API.update_list(slug[, name][, mode][, description])

Updates the specified list. Note: this current throws a 500. Twitter is looking into the issue.

パラメータ:
  • slug – the slug name or numerical ID of the list
  • name – What you’d like to change the lists name to.
  • mode – Whether your list is public or private. Values can be public or private. Lists are public by default if no mode is specified.
  • description – What you’d like to change the list description to.
戻り値の型:

List object

API.lists([cursor])

List the lists of the specified user. Private lists will be included if the authenticated users is the same as the user who’s lists are being returned.

パラメータ:cursor – Breaks the results into pages. Provide a value of -1 to begin paging. Provide values as returned to in the response body’s next_cursor and previous_cursor attributes to page back and forth in the list.
戻り値の型:list of List objects
API.lists_memberships([cursor])

List the lists the specified user has been added to.

パラメータ:cursor – Breaks the results into pages. Provide a value of -1 to begin paging. Provide values as returned to in the response body’s next_cursor and previous_cursor attributes to page back and forth in the list.
戻り値の型:list of List objects
API.lists_subscriptions([cursor])

List the lists the specified user follows.

パラメータ:cursor – Breaks the results into pages. Provide a value of -1 to begin paging. Provide values as returned to in the response body’s next_cursor and previous_cursor attributes to page back and forth in the list.
戻り値の型:list of List objects
API.list_timeline(owner, slug[, since_id][, max_id][, per_page][, page])

Show tweet timeline for members of the specified list.

パラメータ:
  • owner – the screen name of the owner of the list
  • slug – the slug name or numerical ID of the list
  • since_id – Returns only statuses with an ID greater than (that is, more recent than) the specified ID.
  • max_id – Returns only statuses with an ID less than (that is, older than) or equal to the specified ID.
  • per_page – Number of results per a page
  • page – Specifies the page of results to retrieve. Note: there are pagination limits.
戻り値の型:

Status オブジェクトのリスト

API.get_list(owner, slug)

Show the specified list. Private lists will only be shown if the authenticated user owns the specified list.

パラメータ:
  • owner – the screen name of the owner of the list
  • slug – the slug name or numerical ID of the list
戻り値の型:

List object

API.add_list_member(slug, id)

Add a member to a list. The authenticated user must own the list to be able to add members to it. Lists are limited to having 500 members.

パラメータ:
  • slug – the slug name or numerical ID of the list
  • id – the ID of the user to add as a member
戻り値の型:

List object

API.remove_list_member(slug, id)

Removes the specified member from the list. The authenticated user must be the list’s owner to remove members from the list.

パラメータ:
  • slug – the slug name or numerical ID of the list
  • id – the ID of the user to remove as a member
戻り値の型:

List object

API.list_members(owner, slug, cursor)

Returns the members of the specified list.

パラメータ:
  • owner – the screen name of the owner of the list
  • slug – the slug name or numerical ID of the list
  • cursor – Breaks the results into pages. Provide a value of -1 to begin paging. Provide values as returned to in the response body’s next_cursor and previous_cursor attributes to page back and forth in the list.
戻り値の型:

list of User objects

API.is_list_member(owner, slug, id)

Check if a user is a member of the specified list.

パラメータ:
  • owner – the screen name of the owner of the list
  • slug – the slug name or numerical ID of the list
  • id – the ID of the user to check
戻り値の型:

User object if user is a member of list, otherwise False.

API.subscribe_list(owner, slug)

Make the authenticated user follow the specified list.

パラメータ:
  • owner – the screen name of the owner of the list
  • slug – the slug name or numerical ID of the list
戻り値の型:

List object

API.unsubscribe_list(owner, slug)

Unsubscribes the authenticated user form the specified list.

パラメータ:
  • owner – the screen name of the owner of the list
  • slug – the slug name or numerical ID of the list
戻り値の型:

List object

API.list_subscribers(owner, slug[, cursor])

Returns the subscribers of the specified list.

パラメータ:
  • owner – the screen name of the owner of the list
  • slug – the slug name or numerical ID of the list
  • cursor – Breaks the results into pages. Provide a value of -1 to begin paging. Provide values as returned to in the response body’s next_cursor and previous_cursor attributes to page back and forth in the list.
戻り値の型:

list of User objects

API.is_subscribed_list(owner, slug, id)

Check if the specified user is a subscriber of the specified list.

パラメータ:
  • owner – the screen name of the owner of the list
  • slug – the slug name or numerical ID of the list
  • id – the ID of the user to check
戻り値の型:

User object if user is subscribed to the list, otherwise False.

Geo Methods

API.reverse_geocode([lat][, long][, accuracy][, granularity][, max_results])

Given a latitude and longitude, looks for places (cities and neighbourhoods) whose IDs can be specified in a call to update_status() to appear as the name of the location. This call provides a detailed response about the location in question; the nearby_places() function should be preferred for getting a list of places nearby without great detail.

パラメータ:
  • lat – The location’s latitude.
  • long – The location’s longitude.
  • accuracy – Specify the 「region」 in which to search, such as a number (then this is a radius in meters, but it can also take a string that is suffixed with ft to specify feet). If this is not passed in, then it is assumed to be 0m
  • granularity – Assumed to be `neighborhood』 by default; can also be `city』.
  • max_results – A hint as to the maximum number of results to return. This is only a guideline, which may not be adhered to.
API.reverse_geocode([lat][, long][, ip][, accuracy][, granularity][, max_results])

Given a latitude and longitude, looks for nearby places (cities and neighbourhoods) whose IDs can be specified in a call to update_status() to appear as the name of the location. This call provides a detailed response about the location in question; the nearby_places() function should be preferred for getting a list of places nearby without great detail.

パラメータ:
  • lat – The location’s latitude.
  • long – The location’s longitude.
  • ip – The location’s IP address. Twitter will attempt to geolocate using the IP address.
  • accuracy – Specify the 「region」 in which to search, such as a number (then this is a radius in meters, but it can also take a string that is suffixed with ft to specify feet). If this is not passed in, then it is assumed to be 0m
  • granularity – Assumed to be `neighborhood』 by default; can also be `city』.
  • max_results – A hint as to the maximum number of results to return. This is only a guideline, which may not be adhered to.
API.geo_id(id)

Given id of a place, provide more details about that place.

パラメータ:id – Valid Twitter ID of a location.

tweepy.error — Exceptions

The exceptions are available in the tweepy module directly, which means tweepy.error itself does not need to be imported. For example, tweepy.error.TweepError is available as tweepy.TweepError.

exception TweepError

The main exception Tweepy uses. Is raised for a number of things.

When a TweepError is raised due to an error Twitter responded with, the error code (as described in the API documentation) can be accessed at TweepError.message[0]['code']. Note, however, that TweepErrors also may be raised with other things as message (for example plain error reason strings).

exception RateLimitError

Is raised when an API method fails due to hitting Twitter’s rate limit. Makes for easy handling of the rate limit specifically.

Inherits from TweepError, so except TweepError will catch a RateLimitError too.