如何使用 Flask 和 rauth 从 Google API 获取用户信息(用户名/ID)?

How do I obtain user info (username / id) from Google API using Flask and rauth?

这是我目前得到的。

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)

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

解决了问题。 get_access_token 函数有缺陷。 Follow this link for more information