A Python library for OAuth 1.0/a, 2.0, and Ofly.
Project description
# Rauth: OAuth 1.0/a, 2.0, and Ofly for Python
This package provides OAuth 1.0/a, 2.0, and Ofly consumer support. The
package is wrapped around the superb Python Requests.
## Installation
Install the package with one of the following commands:
$ easy_install rauth
or
$ pip install rauth
## Example Usage
Using the package is quite simple. Ensure that Python Requests is installed.
Import the relevant module and start utilizing OAuth endpoints!
Let's get a user's Twitter timeline. Start by creating a service container
object:
from rauth.service import OAuth1Service
# Get a real consumer key & secret from https://dev.twitter.com/apps/new
twitter = OAuth1Service(
name='twitter',
consumer_key='YOUR_CONSUMER_KEY',
consumer_secret='YOUR_CONSUMER_SECRET',
request_token_url='https://api.twitter.com/oauth/request_token',
access_token_url='https://api.twitter.com/oauth/access_token',
authorize_url='https://api.twitter.com/oauth/authorize',
header_auth=True)
Then get an OAuth 1.0 request token:
request_token, request_token_secret = \
twitter.get_request_token(http_method='GET')
Go through the authentication flow. Since our example is a simple console
application, Twitter will give you a PIN to enter.
authorize_url = twitter.get_authorize_url(request_token)
print 'Visit this URL in your browser: ' + authorize_url
pin = raw_input('Enter PIN from browser: ')
Exchange the authorized request token for an access token:
response = twitter.get_access_token(request_token,
request_token_secret,
http_method='GET',
oauth_verifier=pin)
data = response.content
access_token = data['oauth_token']
access_token_secret = data['oauth_token_secret']
And now we can fetch our Twitter timeline!
params = {'include_rts': 1, # Include retweets
'count': 10} # 10 tweets
response = twitter.request(
'GET',
'https://api.twitter.com/1/statuses/home_timeline.json',
access_token,
access_token_secret,
header_auth=True,
params=params)
for i, tweet in enumerate(response.content, 1):
handle = tweet['user']['screen_name'].encode('utf-8')
text = tweet['text'].encode('utf-8')
print '{0}. @{1} - {2}'.format(i, handle, text)
The full example is in [examples/twitter-timeline.py](https://github.com/litl/rauth/blob/master/examples/twitter-timeline.py).
## Documentation
The Sphinx-compiled documentation is available here: [http://packages.python.org/rauth/](http://packages.python.org/rauth/)
## Copyright and License
Rauth is Copyright (c) 2012 litl, LLC and licensed under the MIT license.
See the LICENSE file for full details.
This package provides OAuth 1.0/a, 2.0, and Ofly consumer support. The
package is wrapped around the superb Python Requests.
## Installation
Install the package with one of the following commands:
$ easy_install rauth
or
$ pip install rauth
## Example Usage
Using the package is quite simple. Ensure that Python Requests is installed.
Import the relevant module and start utilizing OAuth endpoints!
Let's get a user's Twitter timeline. Start by creating a service container
object:
from rauth.service import OAuth1Service
# Get a real consumer key & secret from https://dev.twitter.com/apps/new
twitter = OAuth1Service(
name='twitter',
consumer_key='YOUR_CONSUMER_KEY',
consumer_secret='YOUR_CONSUMER_SECRET',
request_token_url='https://api.twitter.com/oauth/request_token',
access_token_url='https://api.twitter.com/oauth/access_token',
authorize_url='https://api.twitter.com/oauth/authorize',
header_auth=True)
Then get an OAuth 1.0 request token:
request_token, request_token_secret = \
twitter.get_request_token(http_method='GET')
Go through the authentication flow. Since our example is a simple console
application, Twitter will give you a PIN to enter.
authorize_url = twitter.get_authorize_url(request_token)
print 'Visit this URL in your browser: ' + authorize_url
pin = raw_input('Enter PIN from browser: ')
Exchange the authorized request token for an access token:
response = twitter.get_access_token(request_token,
request_token_secret,
http_method='GET',
oauth_verifier=pin)
data = response.content
access_token = data['oauth_token']
access_token_secret = data['oauth_token_secret']
And now we can fetch our Twitter timeline!
params = {'include_rts': 1, # Include retweets
'count': 10} # 10 tweets
response = twitter.request(
'GET',
'https://api.twitter.com/1/statuses/home_timeline.json',
access_token,
access_token_secret,
header_auth=True,
params=params)
for i, tweet in enumerate(response.content, 1):
handle = tweet['user']['screen_name'].encode('utf-8')
text = tweet['text'].encode('utf-8')
print '{0}. @{1} - {2}'.format(i, handle, text)
The full example is in [examples/twitter-timeline.py](https://github.com/litl/rauth/blob/master/examples/twitter-timeline.py).
## Documentation
The Sphinx-compiled documentation is available here: [http://packages.python.org/rauth/](http://packages.python.org/rauth/)
## Copyright and License
Rauth is Copyright (c) 2012 litl, LLC and licensed under the MIT license.
See the LICENSE file for full details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
rauth-0.2.4.tar.gz
(11.6 kB
view details)
File details
Details for the file rauth-0.2.4.tar.gz
.
File metadata
- Download URL: rauth-0.2.4.tar.gz
- Upload date:
- Size: 11.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7397286100f733ae98913e599a3a30ff5a8dc658beee7748ffb67b944b02aadb |
|
MD5 | 3c50cc17e715c50b0c9bd609a14fdd2d |
|
BLAKE2b-256 | 5857c0c0a25b2302912dc098739789fce3fafdf5056ca0ec9471a62f50b4e82c |