Flask / Facebook:Flask-Oauth OAuthException:缺少redirect_uri参数?

时间:2013-01-27 00:59:56

标签: python facebook oauth flask

我有一个Flask应用程序,我正在尝试通过Facebook进行身份验证。在本地,它工作得很好。当我部署到Heroku时,它不起作用,抛出以下错误:

{u'error': {u'type': u'OAuthException', u'message': u'Missing redirect_uri parameter.', u'code': 191}}

'Invalid response from facebook'

我已经搜遍了所有的stackoverflow和google以获得答案,但我似乎无法弄明白。

我特别感到困惑的是它为什么在本地工作而没有部署。

关于我的实施,请写信:

facebook = oauth.remote_app('facebook',
    base_url='https://graph.facebook.com/',
    request_token_url=None,
    access_token_url='/oauth/access_token',
    authorize_url='https://www.facebook.com/dialog/oauth',
    consumer_key=FACEBOOK_APP_ID,
    consumer_secret=FACEBOOK_APP_SECRET,
    request_token_params={'scope':'email,user_birthday,user_education_history,user_photos,publish_actions'}
    )

@app.route('/login')
def login():
    return facebook.authorize(callback=url_for('facebook_authorized',
        next=request.args.get('next') or request.referrer or None,
        _external=True))

@app.route('/login/authorized')
@facebook.authorized_handler
def facebook_authorized(resp):
    if resp is None:
        error = 'Access denied: reason=%s error=%s' %(
            request.args['error_reason'],
            request.args['error_descriptions']
        )
        return render_template('home.html', error=error)
    xyz = (resp['access_token'], '')
    session['oauth_token'] = xyz
    me = facebook.get('/me')
    checkUser = db.session.query(User).filter(User.fid==me.data['id']).all()
    if not checkUser:
        fname = me.data['name'].split()[0]
        lname = me.data['name'].split()[-1]
        education=''
        if 'education' in me.data:
            education=me.data['education'][-1]['school']['name']
        newuser = User(me.data['id'], fname, lname, me.data['email'], me.data['username'], education)
        db.session.add(newuser)
        db.session.commit()
    flash('You were logged in')
    session['fid'] = me.data['id']
    return redirect(url_for('home'))

@facebook.tokengetter
def get_facebook_oauth_token():
    return session.get('oauth_token')

任何人都有线索吗?

1 个答案:

答案 0 :(得分:1)

尝试将您的回调网址设为带域等的完整网址。如果您在本地工作,则可以使用localhost,但如果您不在80,请指定端口。