我正在创建一个从 Google Search Console API 检索数据的烧瓶应用程序。
但是,我很难用 Flask-Dance 实现 Google OAuth。
我收到以下错误:
这是我的代码:
from flask import Flask, render_template, request, redirect, url_for
from flask_dance.contrib.google import make_google_blueprint, google
import os
def create_app(config_name):
os.environ['OAUTHLIB_INSECURE_TRANSPORT'] = '1'
os.environ['OAUTHLIB_RELAX_TOKEN_SCOPE'] = '1'
print(config_name)
blueprint = make_google_blueprint(
client_id={MY CLIENT ID},
client_secret={MY SECRET},
scope=["profile", "email"])
app = Flask(__name__)
app.config.from_object(config[config_name])
google_bp = make_google_blueprint(scope=["profile","email","https://www.googleapis.com/auth/webmasters"])
@app.route("/search")
def search():
if not google.authorized:
return redirect(url_for("google.login"))
request = {
'startDate': '2019-01-01',
'endDate': '2019-01-31','dimensions': ['query']}
resp = google.post("/webmasters/v3/sites/https%3A%2F%2Fwww.mysite.com/searchAnalytics/query", json=request)
amt=resp['rows'][0]['clicks']
return '<h1>'+amt+'</h1>'
return app
我还按照以下步骤在 Google Developers Console 中设置了应用程序,如下所述: https ://flask-dance.readthedocs.io/en/v0.8.0/quickstarts/google.html
任何想法可能是什么问题?
提前谢谢了