liluo/py-oauth2

getting the access_token /oath2callback

Closed this issue · 15 comments

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)





app = Flask(__name__)







@app.route("/")

def hello():

    print "hello world"

    return redirect(authorize_url)



@app.route("/oauth2callback")

def oauth2callback():

How do i get access to user info in oauth2callback in this example?

@app.route("/oauth2callback")
def oauth2callback():
    code = request.args.get('code')
    access_token = client.auth_code.get_token(code, redirect_uri=REDIRECT_URL)
    ret = access_token.get('/userinfo')
    print ret.parsed

Get an internal server error with that after i click accept button on google's page...:(

In your code:
code = request.args.get('code')

  • where do i get "request" from?

Thanks. Got it, was from flask. Also: How can i get the user image/profile image from google?

@app.route("/oauth2callback")
def oauth2callback():
    code = request.args.get('code')
    access_token = client.auth_code.get_token(code, redirect_uri=REDIRECT_URL)
    ret = access_token.get('/userinfo')
    print ret.parsed  ## this user info, type dict

ret.parsed

I got that. The dict has all the info I need except the image of the user.

https://oauth2-login-demo.appspot.com/

If you try the above link, the dict returned from google has a "picture" element. I dont see that in the dict I get. Am I missing something?

Got it. Seems like picture is returned for only certain accounts (which have picture set). Otherwise it does not return pictures. Thanks.

I could get google to work, thanks. Do you plan to support facebook anytime soon ? Or perhaps does it already work?

I can't apply the facebook api key :(

Why not? :) Also, have you tested your code on python 3?

Why not?

China, hmm... :neckbeard:

Also, have you tested your code on python 3?

Not yet.

Can you try that please. Python 3 support would be nice.

Any luck with python 3?

@pythonmobile Supported, try it.