使用Google API的Flask_dance;缺少必需参数:refresh_token

问题描述 投票:1回答:1

我试图用flask_dance和Google制作授权系统。我首先成功授权,但过了一段时间,该程序导致了这个错误,即使我根本没有改变它。我的整个代码都在这里(它与教程一样几乎相同

from flask import Flask, redirect, url_for
from flask_dance.contrib.google import make_google_blueprint, google

app = Flask(__name__)
app.secret_key = "supersekrit"
blueprint = make_google_blueprint(
    client_id="",
client_secret="",
scope=["profile", "email"]
)
app.register_blueprint(blueprint, url_prefix="/login")

@app.route("/")
def index():
    if not google.authorized:
        return redirect(url_for("google.login"))
    resp = google.get("/oauth2/v2/userinfo")
    assert resp.ok, resp.text
    return "You are {email} on Google".format(email=resp.json()["email"])

if __name__ == "__main__":
    app.run()

我该如何解决这个错误?

python flask
1个回答
0
投票

这个问题似乎是引用in this Github issue的问题。建议的解决方案是请求离线访问:

google_blueprint = make_google_blueprint(
    client_id='',
    client_secret='',
    scope=['profile', 'email'],
    offline=True
)
© www.soinside.com 2019 - 2024. All rights reserved.