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

如何使用Flask和rauth从Google API获取用户信息(用户名/id)?,flask,google-api,rauth,Flask,Google Api,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/

这是我到目前为止得到的

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)

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

解决了这个问题。
get\u access\u token
功能有缺陷

request.args
在您的回调方法中包含什么样的数据?我正在从烧瓶库导入
request.args
,我知道它是什么。我的意思是,它可能不止是您获取的
code
键。您能帮助我理解我应该如何编写回调过程吗
请求。args['code']
将成为
4/cMmBfo4BbNd87Yk6q0\JsoMmxmhLgretxViW7qKMUK8.4ja0d\bcdymxcp7tdiljkzbyqhcmai
,类型为unicode>