Coder Social home page Coder Social logo

py-oauth2's Introduction

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

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',]
SCOPE = ' '.join(SCOPE)

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')
# got code
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:

https://github.com/liluo/py-oauth2/wiki

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

Demo for QQ

Demo for Taobao

License

MIT

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.

py-oauth2's People

Contributors

alswl avatar liluo avatar waawal avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.