Twitter API

Methods of the tweepy API object

There are a very numerous number of API methods.

import pprint
from hello_world_tweepy import api

pprint.pp(dir(api))
['__class__',
'__delattr__',
'__dict__',
'__dir__',
'__doc__',
'__eq__',
'__format__',
'__ge__',
'__getattribute__',
'__gt__',
'__hash__',
'__init__',
'__init_subclass__',
'__le__',
'__lt__',
'__module__',
'__ne__',
'__new__',
'__reduce__',
'__reduce_ex__',
'__repr__',
'__setattr__',
'__sizeof__',
'__str__',
'__subclasshook__',
'__weakref__',
'_add_list_members',
'_lookup_friendships',
'_pack_image',
'_remove_list_members',
'_send_direct_message',
'add_list_member',
'add_list_members',
'api_root',
'auth',
'blocks',
'blocks_ids',
'cache',
'compression',
'configuration',
'create_block',
'create_favorite',
'create_friendship',
'create_list',
'create_media_metadata',
'create_mute',
'create_saved_search',
'destroy_block',
'destroy_direct_message',
'destroy_favorite',
'destroy_friendship',
'destroy_list',
'destroy_mute',
'destroy_saved_search',
'destroy_status',
'favorites',
'followers',
'followers_ids',
'friends',
'friends_ids',
'friendships_incoming',
'friendships_outgoing',
'geo_id',
'geo_search',
'geo_similar_places',
'get_direct_message',
'get_list',
'get_oembed',
'get_saved_search',
'get_settings',
'get_status',
'get_user',
'home_timeline',
'host',
'list_direct_messages',
'list_members',
'list_subscribers',
'list_timeline',
'lists_all',
'lists_memberships',
'lists_subscriptions',
'lookup_friendships',
'lookup_users',
'me',
'media_upload',
'mentions_timeline',
'mutes',
'mutes_ids',
'parser',
'proxy',
'rate_limit_status',
'related_results',
'remove_list_member',
'remove_list_members',
'report_spam',
'retry_count',
'retry_delay',
'retry_errors',
'retweet',
'retweeters',
'retweets',
'retweets_of_me',
'reverse_geocode',
'saved_searches',
'search',
'search_host',
'search_root',
'search_users',
'send_direct_message',
'set_settings',
'show_friendship',
'show_list_member',
'show_list_subscriber',
'statuses_lookup',
'subscribe_list',
'supported_languages',
'timeout',
'trends_available',
'trends_closest',
'trends_place',
'unretweet',
'unsubscribe_list',
'update_list',
'update_profile',
'update_profile_background_image',
'update_profile_banner',
'update_profile_image',
'update_status',
'update_with_media',
'upload_host',
'upload_root',
'user_timeline',
'verify_credentials',
'wait_on_rate_limit',
]

API

A basic script show casing how to use tweepy.

Tweepy functionality

Over time, the names of various Twitter concepts have evolved, some old names are still used in Tweepy. So keep in mind that, in the context of this article, these equivalences hold:

  • A status is a tweet .

  • A friendship is a follow-follower relationship.

  • A favorite is a like.

Create API object

Objects belonging to the tweepy.API class offer a vast set of methods that you can use to access almost all Twitter functionality. In the code snippet, we used update_status to create a new Tweet.:

# auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
# auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
# api = tweepy.API(auth)

Setting wait_on_rate_limit and wait_on_rate_limit_notify to True makes the API object print a message and wait if the rate limit is exceeded:

Tweepy Categories

Tweepy’s functionality can be divided into the following groups:

  • OAuth

  • The API class

  • Models

  • Cursors

  • Streams

I’ve previously set up my OAuth token’s so we’ll skip those.

API Class

The API methods can be grouped into the following categories:

  • Methods for user timelines

  • Methods for tweets

  • Methods for users

  • Methods for followers

  • Methods for your account

  • Methods for likes

  • Methods for blocking users

  • Methods for searches

  • Methods for trends

  • Methods for streaming

hello_world_tweepy.run_tweepy()

Authenticate to Twitter.