Python Flask-重定向到Google authrozie url源空
我正在尝试从google api获取日历事件。(烧瓶API和角形) 问题是,当我将用户重定向到授权url(使用step1_get_authorize_url方法)时,源标题为空,并且我一直没有收到“Access Control Allow origin”标题错误Python Flask-重定向到Google authrozie url源空,python,flask,google-api,Python,Flask,Google Api,我正在尝试从google api获取日历事件。(烧瓶API和角形) 问题是,当我将用户重定向到授权url(使用step1_get_authorize_url方法)时,源标题为空,并且我一直没有收到“Access Control Allow origin”标题错误 @oauth_api.route('/google/<action>') def getGoogleCalendarRequest(action): if 'credentials' not in session:
@oauth_api.route('/google/<action>')
def getGoogleCalendarRequest(action):
if 'credentials' not in session:
return redirect(url_for('oauth_controller.google'+action.title()+'Callback'))
credentials = client.OAuth2Credentials.from_json(session['credentials'])
if credentials.access_token_expired:
return redirect(url_for('oauth_controller.google'+action.title()+'Callback'))
else:
return session['credentials']
@oauth_api.route('/googleCallback')
def googleCalendarCallback():
flow = client.OAuth2WebServerFlow(
client_id='client_id',
client_secret='client_secret',
scope='https://www.googleapis.com/auth/calendar.readonly',
redirect_uri=url_for('oauth_controller.googleCalendarCallback',
approval_prompt='force',
access_type='offline'))
if 'code' not in request.args:
auth_uri = flow.step1_get_authorize_url()
return redirect(auth_uri)
else:
auth_code = request.args.get('code')
credentials = flow.step2_exchange(auth_code)
session['credentials'] = credentials.to_json()
return redirect(url_for('oauth_controller.getGoogleCalendarRequest'))
@oauth_api.route('/google/'))
def getGoogleCalendarRequest(操作):
如果“凭据”不在会话中:
返回重定向(url_for('oauth_controller.google'+action.title()+'Callback'))
credentials=client.OAuth2Credentials.from_json(会话['credentials'))
如果credentials.access\u令牌\u过期:
返回重定向(url_for('oauth_controller.google'+action.title()+'Callback'))
其他:
返回会话['credentials']
@oauth_api.route('/googleCallback')
def googleCalendarCallback():
flow=client.OAuth2WebServerFlow(
client_id='client_id',
client_secret='client_secret',
范围=https://www.googleapis.com/auth/calendar.readonly',
重定向\u uri=url\u for('oauth\u controller.googleCalendarCallback',
批准,
访问(U type='offline'))
如果request.args中没有“code”:
auth\u uri=flow.step1\u get\u authorize\u url()
返回重定向(auth_uri)
其他:
auth_code=request.args.get('code'))
凭证=流程。步骤2\u交换(验证码)
会话['credentials']=凭证。到_json()
返回重定向(url_for('oauth_controller.getGoogleCalendarRequest'))