| | |
- exceptions.Exception(exceptions.BaseException)
-
- TwitterError
- Api
- GetOauth
- Status
- User
- XMLParser
class Api |
| |
A Python interface to the Twitter API
How To Use:
First, 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/apps
Second, 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 above
Now, 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.
>>> post_update(u'Hello, Twitter')
>>> post_update(u'こんにちは、Twitter')
Methods:
You can use next methods
post_update()
get_user_timeline()
get_friends_timeline()
get_replies()
destroy_status() |
| |
Methods defined here:
- __init__(self, consumer_key, consumer_secret, oauth_token, oauth_token_secret)
- The Api class initializer.
- destroy_status(self, id)
- get_friends_timeline(self, id=None, since_id=None, max_id=None, count=None, page=None)
- get_replies(self, id=None, since_id=None, max_id=None, count=None, page=None)
- get_user_timeline(self, id=None, since_id=None, max_id=None, count=None, page=None)
- post_update(self, tweet='')
- Post your tweet.
|
class GetOauth |
| |
A class for getting consumer_key and consumer_secret. |
| |
Methods defined here:
- __init__(self, consumer_key, consumer_secret)
- GetOauth initializer.
- get_oauth(self)
- Get consumer_key and consumer_secret.
How to use:
>>> import twitter_oauth
>>> consumer_key = '***'
>>> consumer_secret = '***'
>>> get_oauth_obj = twitter_oauth.GetOauht(consumer_key, consumer_secret)
>>> get_oauth_obj.get_oauth()
|
class Status |
| |
A class representing a status.
The Status class have next attributes:
stauts.created_at
stauts.id
stauts.text
stauts.source
stauts.truncated
stauts.in_reply_to_status_id
stauts.in_reply_to_user_id
stauts.favorited
stauts.user
stauts.geo
stauts.contributors
The Status class have next methods:
status.get_created_at_from_now()
status.get_created_at_in_utc()
status.get_created_at_in_jsp() |
| |
Methods defined here:
- __init__(self, created_at=None, id=None, text=None, source=None, truncated=None, in_reply_to_status_id=None, in_reply_to_user_id=None, favorited=None, user=None, geo=None, contributors=None)
- Status class initializer.
- get_created_at_from_now(self)
- When created from now
- get_created_at_in_jsp(self)
- return datetime.datetime object in JSP
- get_created_at_in_utc(self)
- return datetime.datetime object in UTC
|
class User |
| |
A class representing User.
The User class have next attributes:
user.id
user.name
user.screen_name
user.created_at
user.location
user.description
user.url
user.protected
user.followers_count
user.friends_count
user.favourites_count
user.statuses_count
user.profile_image_url
user.profile_background_color
user.profile_text_color
user.profile_link_color
user.profile_sidebar_fill_color
user.profile_sidebar_border_color
user.profile_background_image_url
user.profile_background_tile
user.utc_offset
user.time_zone
user.lang
user.geo_enabled
user.verified
user.notifications
user.following
user.contributors_enabled
The Status class have next methods:
status.get_created_at_in_utc()
status.get_created_at_in_jsp() |
| |
Methods defined here:
- __init__(self, id=None, name=None, screen_name=None, created_at=None, location=None, description=None, url=None, protected=None, followers_count=None, friends_count=None, favourites_count=None, statuses_count=None, profile_image_url=None, profile_background_color=None, profile_text_color=None, profile_link_color=None, profile_sidebar_fill_color=None, profile_sidebar_border_color=None, profile_background_image_url=None, profile_background_tile=None, utc_offset=None, time_zone=None, lang=None, geo_enabled=None, verified=None, notifications=None, following=None, contributors_enabled=None)
- get_created_at_in_jsp(self)
- return datetime.datetime object in JSP
- get_created_at_in_utc(self)
- return datetime.datetime object in UTC
|
|