使用Facebook API的Flask_dance;缺少访问令牌参数

时间:2018-06-06 09:04:00

标签: flask oauth-2.0

我在flask_dance扩展中遇到另一个问题,在我点击Facebook注册按钮并允许该应用访问我的Facebook帐户后,我被成功重定向到我的网站,但有错误说:

oauthlib.oauth2.rfc6749.errors.MissingTokenError MissingTokenError: (missing_token) Missing access token parameter.

这是我的代码:

from flask_dance.contrib.facebook import make_facebook_blueprint, facebook

facebook_blueprint = make_facebook_blueprint(
    client_id=app.config['FACEBOOK_CLIENT_ID'],
    client_secret=app.config['FACEBOOK_CLIENT_SECRET'],
    scope=["email", "public_profile"]
)
app.register_blueprint(facebook_blueprint)

    @oauth_authorized.connect_via(facebook_blueprint)
    def facebook_logged_in(blueprint, token):
        resp = blueprint.session.get("/me?&fields={fields}".format(fields=['name','picture', 'email', 'verified']))
        if resp.ok:
            account_info_json = resp.json()
            email = account_info_json['email']

            query = User.query.filter_by(email=email)

            try:

                user = query.one()
                user.image = account_info_json['picture']['data']['url']
                db.session.commit()

            except NoResultFound:
                user = User()
                user.image = account_info_json['picture']['data']['url']
                user.username = account_info_json['name']
                user.email = account_info_json['email']

                if account_info_json['verified'] == True:
                    user.confirmed = True
                    user.is_admin = False

                db.session.add(user)
                db.session.commit()

            login_user(user)

            identity_changed.send(
                current_app._get_current_object(),
                identity=Identity(user.id)
            )

0 个答案:

没有答案