Welcome, guest | Sign In | My Account | Store | Cart

Notice! PyPM is being replaced with the ActiveState Platform, which enhances PyPM’s build and deploy capabilities. Create your free Platform account to download ActivePython or customize Python with the packages you require and get automatic updates.

Download
ActivePython
INSTALL>
pypm install py-oauth2

How to install py-oauth2

  1. Download and install ActivePython
  2. Open Command Prompt
  3. Type pypm install py-oauth2
 Python 2.7Python 3.2Python 3.3
Windows (32-bit)
0.0.5
0.0.6Never BuiltWhy not?
0.0.5 Available View build log
0.0.4 Available View build log
Windows (64-bit)
0.0.5
0.0.6Never BuiltWhy not?
0.0.5 Available View build log
Mac OS X (10.5+)
0.0.5
0.0.6Never BuiltWhy not?
0.0.5 Available View build log
0.0.4 Available View build log
Linux (32-bit)
0.0.5
0.0.6Never BuiltWhy not?
0.0.5 Available View build log
0.0.4 Available View build log
0.0.3 Available View build log
0.0.2 Available View build log
Linux (64-bit)
0.0.6 Available View build log
0.0.5 Available View build log
0.0.4 Available View build log
0.0.3 Available View build log
0.0.2 Available View build log
 
Author
License
MIT License
Dependencies
Depended by
Lastest release
version 0.0.6 on Jan 9th, 2014

A Python wrapper for the OAuth 2.0 specification

Installation

pip:

pip install py-oauth2

easy_install:

easy_install py-oauth2

Warning

if the py-oauth2 version is less than 0.0.5,pls use import oauth2 instead.:

from oauth2 import Client

else:

from pyoauth2 import Client

Usage Examples

Demo for Google

Get user info:

from pyoauth2 import Client

CLIENT_ID = ''
CLIENT_SECRET = ''
REDIRECT_URL = ''
SCOPE = 'https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email'

client = Client(CLIENT_ID, CLIENT_SECRET,
                site='https://www.googleapis.com/oauth2/v1',
                authorize_url='https://accounts.google.com/o/oauth2/auth',
                token_url='https://accounts.google.com/o/oauth2/token')

print '-' * 80
authorize_url = client.auth_code.authorize_url(redirect_uri=REDIRECT_URL, scope=SCOPE)
print 'Go to the following link in your browser:'
print authorize_url

code = raw_input('Enter the verification code and hit ENTER when you\'re done:')
code = code.strip()
access_token = client.auth_code.get_token(code, redirect_uri=REDIRECT_URL)
print 'token', access_token.headers

print '-' * 80
print 'get user info'
ret = access_token.get('/userinfo')
print ret.parsed

Demo for Douban

Get access_token:

from pyoauth2 import Client

KEY = ''
SECRET = ''
CALLBACK = ''

client = Client(KEY, SECRET,
                site='https://api.douban.com',
                authorize_url='https://www.douban.com/service/auth2/auth',
                token_url='https://www.douban.com/service/auth2/token')

authorize_url = client.auth_code.authorize_url(redirect_uri=CALLBACK, scope='shuo_basic_w,douban_basic_common')

access_token = client.auth_code.get_token(code, redirect_uri=CALLBACK)

Get data:

ret = access_token.get('/v2/user/~me')
print ret.parsed

Upload image:

ret = access_token.post('/shuo/v2/statuses/', text='content from py-oauth2', files={ 'image': open('/path/pic.jpg')})
print ret.parsed

More:

Examples

Demo for Google

Demo for Douban(auth with code)

Demo for Douban(auth with token)

Demo for Douban(auth with password)

Demo for GitHub

Demo for Weibo

Submitting a Pull Request

  • Fork the repository.
  • Create a topic branch.
  • Implement your feature or bug fix.
  • Add, commit, and push your changes.
  • Submit a pull request.

Subscribe to package updates

Last updated Jan 9th, 2014

Download Stats

Last month:2

What does the lock icon mean?

Builds marked with a lock icon are only available via PyPM to users with a current ActivePython Business Edition subscription.

Need custom builds or support?

ActivePython Enterprise Edition guarantees priority access to technical support, indemnification, expert consulting and quality-assured language builds.

Plan on re-distributing ActivePython?

Get re-distribution rights and eliminate legal risks with ActivePython OEM Edition.