Package: twitter_oauth
These are four contents.RequiredInstallationTutorialSample CodeWhat is changed from version 0.1.0 to 0.2.0Using json data in version 0.2.0You can use more methods in version 0.2.0 than 0.1.0Especially, you can use search methods in version 0.2.0RequiredTwitter_oauth requires Python 2.x superior to 2.5.These modules are required.oauth2If you use python 2.5, you also needsimplejsonInstallationOn Linux.install simplejsonIf you use Python 2.x superior to Python 2.6, skipinstall simplejsonand go toinstall twitter_oauthIf you use python2.5, you should install simplejson first.Download simplejson fromhttp://pypi.python.org/pypi/simplejson/Then, change the directory which contains simplejson file, and$ tar vxzf simplejson-2.1.1.tar.gz
$ cd simplejson-2.1.1
$ sudo python setup.py installinstall twitter_oauthFrom PyPI:$ sudo easy_install twitter_oauthTutorialOAuthFirst, you shold have two keys,
‘consumer key’, ‘consumer secret’.If you don’t have ‘consumer key’ and ‘consumer secret’,
you cat get these keys to register your application to Twitter.
You cat register your application at next URL.http://twitter.com/appsThen, you shold get two keys, ‘oauth_token’, and ‘oauth_token_secret’To get these keys, you use GetOauth class in this module.>>> import twitter_oauth

>>> # write your key and secret
>>> consumer_key = '***'
>>> consumer_secret = '***'

>>> get_oauth_obj = twitter_oauth.GetOauth(consumer_key, consumer_secret)Then, you get ‘oauth_token’ and ‘oauth_token_secret’ by using get_oauth method.
This method returns a dictionary that contain ‘consumer key’, ‘consumer secret’,
‘oauth_token’ and ‘oauth_token_secret’>>> get_oauth_obj.get_oauth()
  Request Token:
  - oauth_token        = ***
  - oauth_token_secret = ***
  Go to the following link in your browser
  http://twitter.com/oauth/authorize?oauth_token=***

  What is the PIN? ***
  Access Token:
  - oauth_token        = ***
  - oauth_token_secret = ***

  You may now access protected resources using the access token aboveApi classNow, you can use twitter_oauth.Api class.
To use this class, you can post update, or get friends timeline, etc…Next example is how to use twitter_oauth.Api class>>> # import twitter_oauth module
>>> import twitter_oauth

>>> # write yoru consumer_key, consumer_secret,
>>> # oauth_token, oauth_token_secret
>>> consumer_key = '***'
>>> consumer_secret = '***'
>>> oauth_token        = '***'
>>> oauth_token_secret = '***'

>>> # Then, create Api instance

>>> api = twitter_oauth.Api(consumer_key, consumer_secret,
>>>                         oauth_token, oauth_token_secret)Use get_friends_timeline method.
You can get friends timeline to use this method.>>> friends_timeline = api.get_friends_timeline()
>>> print [stauts.text for status in friends_timeline]

Use get_user_timeline method.
You can get user timeline to use this method.

>>> user_timeline = api.get_user_timeline()
>>> print [stauts.text for status in user_timeline]

Use get_replies method.
You can get replies to use this method.

>>> replies = api.get_replies()
>>> print [stauts.text for status in replies]Use post_update method
You can post message to Twitter.CAUTION : post_update method shold take a unicode.
Especially, you can post a Japanese text.>>> api.post_update(tweet=u'Hello, Twitter')Use get_list_status method.>>> # write username and list name
>>> api.get_list_status(user='username', list_id='listname')
>>> print [status.text for status in api.get_list_status(user="username", list_id="listname")]Use search methodIf you want to show tweets including ‘keyword’,>>> search_obj = api.search(q='keyword')
>>> print [tweet_info.text for tweet_info in search_obj.results]If you want to show tweets including ‘keyword’ and ‘anotherkeyword’,>>> search_obj = api.search(q='keyword anotherkeyword')
>>> print [tweet_info.text for tweet_info in search_obj.results]If you want to show tweets including ‘keyword’ or ‘anotherkeyword’,>>> search_obj = api.search(q='keyword OR anotherkeyword')
>>> print [tweet_info.text for tweet_info in search_obj.results]If you want to show  timeline from ‘user’,>>> search_obj = api.search(q='from:user')
>>> print [tweet_info.text for tweet_info in search_obj.results]If you want to show tweets to ‘user’, then>>> search_obj = api.search(q='to:user')
>>> print [tweet_info.text for tweet_info in search_obj.results]If you want to show tweets from ‘user’ to ‘another’, then>>> search_obj = api.search(q='from:user to:another')
>>> print [tweet_info.text for tweet_info in search_obj.results]If you want to search tag,>>> search_obj = api.search(q='#twitter')
>>> print [tweet_info.text for tweet_info in search_obj.results]To know more information about a search method, see the next link.http://dev.twitter.com/doc/get/searchMethodsYou can use next methodsstatuspost_update()show_status()destroy_status()timelineget_user_timeline()get_friends_timeline()get_replies()listget_list_status()friendshipcreate_friendship()destroy_friendship()usersearch_user()show_user()searchsearch()Sample Code#! /usr/bin/env python
# coding:utf-8

import twitter_oauth

# write your oauth token and oauth token secret
consumer_key = '***'
consumer_secret = '***'

# create GetOauth instance
get_oauth_obj = twitter_oauth.GetOauth(consumer_key, consumer_secret)

# get oauth_token and oauth token secret
key_dict = get_oauth_obj.get_oauth()

# create Api instance
api = twitter_oauth.Api(consumer_key, consumer_secret, key_dict['oauth_token'], key_dict['oauth_token_secret'])


## timeline method

# get friends timeline
print [status.text for status in api.get_friends_timeline()]

# get user timeline
print [status.text for status in api.get_user_timeline()]

# get replies
print [status.text for status in api.get_replies()]


## status method

# post update
api.post_update(tweet=u'Hello, Twitter')

# show status and destroy status
status = api.get_user_timeline()[0]

print api.show_status(id=status.id).text
api.destroy_status(id=status.id)


## friendship method

api.create_friendship(id='twitter')
api.destroy_friendship(id='twitter')


## user method
print api.show_user(id='twitter').screen_name
print [user.screen_name for user in api.search_user(q='twitter')]


## search method

print [tweet_info.text for tweet_info in api.search(q='#twitter').results]