Skip to content
This repository has been archived by the owner on Feb 9, 2023. It is now read-only.
/ python-twitapi Public archive

Python client library for the Twitter API. Full support for OAuth and Basic Authentication, based on python-oauth2 and httplib2.

License

Notifications You must be signed in to change notification settings

rlr/python-twitapi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

python-twitapi

Info:Python client library for the Twitter API.
Author: Ricky Rosario (http://github.com/rlr)

About

Python-twitapi is a python client library for the Twitter API with full support for OAuth and Basic Authentication. It is based on python-oauth2 and httplib2.

Installation

Fill me in...

Dependencies

Examples

Search:

>>> from twitapi import Client
>>> twitter = Client() # search API doesn't require authentication
>>> resp, content = twitter.search('python')
>>> if resp['status'] == '200':
...     for tweet in content['results']:
...         # do something with the tweet
...         pass

Post a tweet - Basic Authentication:

>>> from twitapi import BasicAuth, Client
>>> auth = BasicAuth('username', 'password')
>>> twitter = Client(auth)
>>> twitter.statuses_update('testing out python-twitapi')

Add a friend - OAuth:

>>> from twitapi import OAuth, Client

# The very first (one-time) thing we need to do is set up an OAuth application
# on Twitter at http://twitter.com/oauth_clients. We will get a consumer key and
# consumer secret for our application.
>>> CONSUMER_KEY = 'YOUR-CONSUMER-KEY'
>>> CONSUMER_SECRET = 'YOUR-CONSUMER-SECRET'

# The first step is getting access tokens for a given user, by having them
# authorize our application.
>>> auth = OAuth(CONSUMER_KEY, CONSUMER_SECRET)
>>> request_token = auth.get_request_token()
>>> auth.get_authorization_url(request_token)
'http://twitter.com/oauth/authorize?oauth_token=G5rvsVRSSz6g48QQ8pbAKDZNBpgxBM6u81BMeZXBk'

# Next we send the user to the URL above. Once they authorize the application,
# we can get the access tokens.
>>> auth.set_token(request_token)
>>> access_token = auth.get_access_token()

# We usually will want to save this access token in our data store for
# later use.

# Now we can call the Twitter API on behalf of the user!
>>> auth.set_token(access_token)
>>> twitter = Client(auth)
>>> twitter.friendships_create(screen_name='r1cky')

Twitter API Methods

The following methods are currently implemented:

* search
* trends
* trends_current
* trends_daily
* trends_weekly
* statuses_home_timeline
* statuses_friends_timeline
* statuses_user_timeline
* statuses_mentions
* statuses_retweeted_by_me
* statuses_retweeted_to_me
* statuses_retweeted_of_me
* statuses_show
* statuses_update
* statuses_destroy
* statuses_retweet
* statuses_retweets
* users_show
* users_lookup
* users_search
* users_suggestions
* users_suggestions_category
* statuses_friends
* statuses_followers
* create_list
* update_list
* get_lists
* get_list
* delete_list
* get_list_statuses
* get_list_memberships
* get_list_subscriptions
* get_list_members
* add_list_member
* delete_list_member
* get_list_members_id
* get_list_subscribers
* subscribe_to_list
* unsubscribe_from_list
* get_list_subscribers_id
* direct_messages
* direct_messages_sent
* direct_messages_new
* direct_messages_destroy
* friendships_create
* friendships_destroy
* friendships_exists
* friends_ids
* followers_ids
* rate_limit_status

The rest are coming. In the mean time, you can call the request method, passing in any url (method, body, headers are optional parameters). For example:

>>> from twitapi import Client
>>> twitter = Client()
>>> url = 'http://api.twitter.com/1/account/rate_limit_status.json'
>>> resp,content = twitter.request(url)
>>> content
{'reset_time': 'Tue Mar 23 03:20:55 +0000 2010', 'remaining_hits': 19028,
'hourly_limit': 20000, 'reset_time_in_seconds': 1269314455}

Or even better, fork and contribute!

Feedback Welcome

Please send me any questions and suggestions on how to improve the project!

About

Python client library for the Twitter API. Full support for OAuth and Basic Authentication, based on python-oauth2 and httplib2.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages