rauth

A Python library for OAuth 1.0/a, 2.0, and Ofly
Download

rauth Ranking & Summary

Advertisement

  • Rating:
  • License:
  • MIT/X Consortium Lic...
  • Price:
  • FREE
  • Publisher Name:
  • Max Countryman
  • Publisher web site:
  • https://github.com/maxcountryman/

rauth Tags


rauth Description

rauth provides OAuth 1.0/a, 2.0, and Ofly consumer support. The package is wrapped around the superb Python Requests.InstallationInstall the package with one of the following commands: easy_install rauthor pip install rauthExample UsageUsing the package is quite simple. Ensure that Python Requests is installed. Import the relavent 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 access_token_secret = dataAnd 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.encode('utf-8') text = tweet.encode('utf-8') print '{0}. @{1} - {2}'.format(i, handle, text)The full example is in (https://github.com/litl/rauth/blob/master/examples/twitter-timeline.py).Product's homepage


rauth Related Software