0

这是我到目前为止所得到的。

GOOGLE_AUTH_URI = 'https://accounts.google.com/o/oauth2/auth'
GOOGLE_REVOKE_URI = 'https://accounts.google.com/o/oauth2/revoke'
GOOGLE_TOKEN_URI = 'https://accounts.google.com/o/oauth2/token'
GOOGLE_BASE_URL = 'https://www.googleapis.com/plus/v1/'

redirect_uri = '127.0.0.1:5000/callback'    

google = OAuth2Service(
name='google',
client_id = GOOGLE_APP_ID,
client_secret = GOOGLE_APP_SECRET,
access_token_url=GOOGLE_TOKEN_URI,
authorize_url=GOOGLE_AUTH_URI,
base_url = GOOGLE_BASE_URL)


@app.route('/login/google')
def googleLogin():
params = {'scope': 'https://www.googleapis.com/auth/userinfo.profile',
          'access_type': 'offline',
          'response_type': 'code',
          'redirect_uri': redirect_uri}
return redirect(google.get_authorize_url(**params))

@app.route('/callback')
def callback():
    credentials = google.get_access_token(data = {'code':request.args['code'],
        'grant_type': 'authorization_code',
        'redirect_uri': redirect_uri},
        decoder = json.loads)

    return jsonify(refresh_token=credentials)

现在我想在用户同意后将用户信息存储在我的数据库中。我该怎么做呢?

4

1 回答 1

2

想通了问题。get_access_token功能有缺陷。点击此链接了解更多信息

于 2015-03-19T00:25:09.900 回答