【问题标题】:Flask_dance with Google API; Missing required parameter: refresh_tokenFlask_dance 与 Google API;缺少必需参数:refresh_token
【发布时间】:2018-03-31 20:59:32
【问题描述】:

我尝试使用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】:

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

    google_blueprint = make_google_blueprint(
        client_id='',
        client_secret='',
        scope=['profile', 'email'],
        offline=True
    )
    

    【讨论】:

      猜你喜欢
      • 2021-10-23
      • 1970-01-01
      • 2016-12-14
      • 2016-04-14
      • 1970-01-01
      • 1970-01-01
      • 2012-06-27
      • 2015-07-13
      • 2012-01-02
      相关资源
      最近更新 更多